Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

Is the Cordova Device UUID the same as the Capacitor Device UUID?

We are migrating from an Ionic Cordova app to an Ionic Capacitor app. While I know that Capacitor still supports Cordova plugins, we try to migrate as much as possible.

Our app relies on the device UUID provided by the Cordova device plugin. Is this the same as the device UUID provided by Capacitor? I tried to compare both repositories, but I am not completely sure if the Android is actually the same (what is the first argument in the method given below)?

Here is my comparison:

iOS Cordova:

[[device identifierForVendor] UUIDString]

Source: 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);

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

iOS Capacitor:

UIDevice.current.identifierForVendor!.uuidString

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

Android Capacitor:

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

iOS

Its the same. The only difference in the case of iOS is the way uuidString is accessed. The Cordova plugin was written in Objective-C while the Capacitor plugin is Swift. The same value should be returned for both though.

Android

The Android plugins also seems to be referencing the same value, just in different ways. Both pass a content resolver from the app Activity context as the first parameter to Settings.Secure.getString(). The difference between: this.context.getContentResolver() and this.cordova.getActivity().getContentResolver() is how Context is accessed (a big topic on Android development).

Cordova Plugin

From the Cordova plugin guidelines,

getContext() and getActivity() can return the required Context object

Capacitor Plugin

If you go through the code of the Capacitor plugin, the file that is the main entry point calls getContext() and directly passed it to the Device() constructor.

In short both refer to the same Activity Context. this.context is the same as this.cordova.getActivity()


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...