【发布时间】:2017-12-09 23:44:39
【问题描述】:
问题在于 ios 设备,当用户卸载并重新安装应用程序时,它会生成新的 UUID,它不是唯一的。
在 android 设备上,我们可以获得唯一的设备 UUID。
【问题讨论】:
标签: ios cordova phonegap-build uuid keychain
问题在于 ios 设备,当用户卸载并重新安装应用程序时,它会生成新的 UUID,它不是唯一的。
在 android 设备上,我们可以获得唯一的设备 UUID。
【问题讨论】:
标签: ios cordova phonegap-build uuid keychain
这就是我的诀窍。它对我有用。
使用钥匙串插件
Keychain 插件允许您在 iOS 中安全地存储数据 钥匙扣。
您可以使用此插件设置、获取和删除钥匙串中的值。 钥匙串中存储的项目在卸载和重新安装您的 应用程序。该数据不可用于任何其他应用程序,除非已签名 具有相同的配置文件。当用户备份 iOS 数据时, 备份钥匙串数据,但钥匙串中的秘密仍然存在 在备份中加密。
钥匙串将数据存储为键值对。您需要设置并获取 这些对使用相同的服务名称。如果您设置现有密钥 使用新值,旧值将被覆盖
Phonegap Build 用户只需将此插件用于 config.xml 文件
<plugin name="cordova-keychain" source="npm" />
如何在 App 中使用?
// prepare some variables
var servicename = 'MyAppUUID';
var key = 'MyApp';
var value = 'Your UUID'; // Set your Device Id here.
// prepare the callback functions
function onSuccess (msg) {alert(msg)};
function onError (msg) {alert(msg)};
// store your password in the Keychain
new Keychain().setForKey(onSuccess, onError, key, servicename, value);
// get your password from the Keychain
new Keychain().getForKey(onSuccess, onError, key, servicename);
// remove your password from the Keychain
new Keychain().removeForKey(onSuccess, onError, key, servicename);
【讨论】: