代码之家  ›  专栏  ›  技术社区  ›  andreas

Cordova设备UUID与电容器设备UUID相同吗?

  •  0
  • andreas  · 技术社区  · 5 年前

    我们正在从Ionic Cordova应用程序迁移到Ionic电容器应用程序。虽然我知道电容器仍然支持Cordova插件,但我们尽可能多地进行迁移。

    我们的应用程序依赖于Cordova设备插件提供的设备UUID。这与电容器提供的设备UUID相同吗?我试图比较两个存储库,但我不完全确定Android是否真的相同(下面给出的方法中的第一个参数是什么)?

    以下是我的比较:

    iOS Cordova:

    [[device identifierForVendor] UUIDString]

    资料来源: https://github.com/apache/cordova-plugin-device/blob/2fc1d3cac0ed37a37de6a6aa18e7955342037a1d/src/ios/CDVDevice.m#L52-L74

    Android Cordova:

    Settings.Secure.getString(this.cordova.getActivity().getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);

    资料来源: https://github.com/apache/cordova-plugin-device/blob/2fc1d3cac0ed37a37de6a6aa18e7955342037a1d/src/android/Device.java#L111-L114

    iOS电容器:

    UIDevice.current.identifierForVendor!.uuidString

    资料来源: https://github.com/ionic-team/capacitor-plugins/blob/0bcd833a6503061be45253b21fca9bd75576efc8/device/ios/Plugin/DevicePlugin.swift#L28

    安卓电容器:

    Settings.Secure.getString(this.context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);

    资料来源: https://github.com/ionic-team/capacitor-plugins/blob/0bcd833a6503061be45253b21fca9bd75576efc8/device/android/src/main/java/com/capacitorjs/plugins/device/Device.java#L43-L45

    0 回复  |  直到 5 年前
        1
  •  1
  •   johnborges    5 年前

    网间网操作系统

    都一样。iOS的唯一区别在于方式 uuidString 被访问。Cordova插件是用Objective-C编写的,而电容器插件是Swift。但是,这两个函数都应该返回相同的值。

    安卓

    Android插件似乎也在以不同的方式引用相同的值。两者都将应用程序活动上下文中的内容解析器作为第一个参数传递给 Settings.Secure.getString() .两者之间的区别: this.context.getContentResolver() this.cordova.getActivity().getContentResolver() 是如何访问上下文(一个大问题) topic 关于Android开发)。

    Cordova插件

    来自Cordova插件 guidelines ,

    getContext()和getActivity()可以返回所需的上下文对象

    电容器插件

    如果你浏览电容器插件的代码 file 这是主要的切入点 getContext() 然后直接传给了 Device() constructor .

    简而言之,两者都指相同的活动上下文。 this.context this.cordova.getActivity()

    推荐文章