cordova - Cordova 设备 UUID 是否与电容器设备 UUID 相同?
问题描述
我们正在从 Ionic Cordova 应用程序迁移到 Ionic Capacitor 应用程序。虽然我知道 Capacitor 仍然支持 Cordova 插件,但我们尝试尽可能多地迁移。
我们的应用依赖于 Cordova 设备插件提供的设备 UUID。这和Capacitor提供的设备UUID一样吗?我试图比较两个存储库,但我不完全确定 Android 是否真的相同(下面给出的方法中的第一个参数是什么)?
这是我的比较:
iOS 科尔多瓦:
[[device identifierForVendor] UUIDString]
安卓科尔多瓦:
Settings.Secure.getString(this.cordova.getActivity().getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
iOS 电容:
UIDevice.current.identifierForVendor!.uuidString
安卓电容:
Settings.Secure.getString(this.context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
解决方案
iOS
一样的。在 iOS 的情况下,唯一的区别uuidString
是访问方式。Cordova 插件是用 Objective-C 编写的,而 Capacitor 插件是 Swift 的。不过,两者都应该返回相同的值。
安卓
Android 插件似乎也引用了相同的值,只是方式不同。两者都将应用活动上下文中的内容解析器作为第一个参数传递给Settings.Secure.getString()
. this.context.getContentResolver()
和之间的区别this.cordova.getActivity().getContentResolver()
是如何访问 Context(Android 开发的一个大话题)。
科尔多瓦插件
根据 Cordova 插件指南,
getContext() 和 getActivity() 可以返回所需的 Context 对象
电容插件
如果您浏览 Capacitor 插件的代码,则作为主入口点的文件调用getContext()
并直接将其传递给Device()
构造函数。
简而言之,两者都指的是相同的活动上下文。this.context
是相同的this.cordova.getActivity()
推荐阅读
- hibernate - doInHibernate 是模棱两可的
- git - Git用来自不同分支的相同文件覆盖master中的文件
- python - 在 python 中使用 selenium 使用 xPath 查找元素的问题
- c# - 未连接到 WiFi 网络时启动内置 Windows MobileHotspot
- node.js - 可以将用户身份验证令牌作为全局变量(process.env)存储在 nodejs lambda 函数中吗?
- loops - 实时计算逻辑图会遗漏很多结果
- javascript - 有没有一种方法可以避免用户从锚点拖动边缘?
- html - CSS网格不适合我,它以不同的方式组织跨度
- html - 关于自定义字体的困惑
- regex - 只返回不包含特定单词的行