【问题标题】:Is the Cordova Device UUID the same as the Capacitor Device UUID?Cordova 设备 UUID 是否与电容器设备 UUID 相同?
【发布时间】:2021-04-17 12:19:07
【问题描述】:

我们正在从 Ionic Cordova 应用迁移到 Ionic Capacitor 应用。虽然我知道 Capacitor 仍然支持 Cordova 插件,但我们会尽量迁移。

我们的应用依赖于 Cordova 设备插件提供的设备 UUID。这和Capacitor提供的设备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

Android 电容:

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

【问题讨论】:

    标签: cordova cordova-plugins capacitor capacitor-plugin


    【解决方案1】:

    iOS

    它是一样的。 iOS 的唯一区别是访问uuidString 的方式。 Cordova 插件是用 Objective-C 编写的,而 Capacitor 插件是 Swift 的。两者都应该返回相同的值。

    安卓

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

    科尔多瓦插件

    来自 Cordova 插件 guidelines

    getContext()和getActivity()可以返回需要的Context对象

    电容插件

    如果你通过Capacitor插件的代码,作为主入口点的file调用getContext()并直接传递给Device()constructor

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

    【讨论】:

    • Swift/Objective-C 的比较很清楚,它是相同的代码。 this.context.getContentResolver()this.cordova.getActivity().getContentResolver() 有什么区别?我无法理解这个值在做什么。
    • @andreas,看看我更新的答案。
    猜你喜欢
    • 1970-01-01
    • 2015-02-03
    • 2015-09-10
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    • 2013-01-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多