Cordova-IOS 如何获取 iPhone UUID 或替代标识符
Cordova-IOS How to get iPhone UUID or alternative identifier
我正在开发基于 Cordova 的应用程序,出于安全原因,我需要在向服务器端发送任何请求之前识别设备
但您可能知道,Apple 现在禁止以任何方式识别设备。
我试过很多插件,但它似乎只在 android 上工作,在 IOS 上它只能识别应用程序而不是设备我也试过原生 objective C 代码,如
[[[UIDevice currentDevice] identifierForVendor] UUIDString]
但它在删除应用程序并重新安装时也发生了变化
任何关于如何使用 UDID 或 IMEI 或任何其他替代
识别 iPhone 的建议
为什么不使用具有 device.uuid
方法并适用于 Android 和 IOS 的标准 cordova-plugin-device
?
参见:https://github.com/apache/cordova-plugin-device#deviceuuid
Get the device's Universally Unique Identifier (UUID).
var string = device.uuid;
在 KeyChain 中保留 identifierForVendor 或自定义 UUID。
删除应用程序并重新安装它不会改变。
见:
How to preserve identifierForVendor in ios after uninstalling ios app on device?
更多..
我没有使用 Cordova,但我知道混合应用程序是如何工作的。
- 创建iOS管理器(get、set、remove)KeyChain的本地方法。
- 创建 iOS 创建 UUID 的本机方法。
- 让 Cordova 使用本机方法:http://cordova.apache.org/docs/en/2.5.0/guide_plugin-development_ios_index.md.html
如果你不想自己做,使用我找到的插件:
http://plugins.cordova.io/#/package/com.crypho.plugins.securestorage
要么
http://plugins.cordova.io/#/package/com.shazron.cordova.plugin.keychainutil
但是你应该检查它们是否正常工作。
Reming Hsu 保存任何 UDID 的想法是正确的,即使它是用于钥匙串中的应用程序然后重用它非常有效,这是完整的代码
NSString *myUUID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"myApp" accessGroup:nil];
if ([[keychainItem objectForKey:(__bridge id)kSecAttrAccount] length]) {
NSString *imeiFromK = [keychainItem objectForKey:(__bridge id)(kSecAttrAccount)];
}
else {
[keychainItem setObject:myUUID forKey:(__bridge id)(kSecAttrAccount)];
}
我正在开发基于 Cordova 的应用程序,出于安全原因,我需要在向服务器端发送任何请求之前识别设备
但您可能知道,Apple 现在禁止以任何方式识别设备。
我试过很多插件,但它似乎只在 android 上工作,在 IOS 上它只能识别应用程序而不是设备我也试过原生 objective C 代码,如
[[[UIDevice currentDevice] identifierForVendor] UUIDString]
但它在删除应用程序并重新安装时也发生了变化
任何关于如何使用 UDID 或 IMEI 或任何其他替代
识别 iPhone 的建议为什么不使用具有 device.uuid
方法并适用于 Android 和 IOS 的标准 cordova-plugin-device
?
参见:https://github.com/apache/cordova-plugin-device#deviceuuid
Get the device's Universally Unique Identifier (UUID).
var string = device.uuid;
在 KeyChain 中保留 identifierForVendor 或自定义 UUID。
删除应用程序并重新安装它不会改变。
见: How to preserve identifierForVendor in ios after uninstalling ios app on device?
更多..
我没有使用 Cordova,但我知道混合应用程序是如何工作的。
- 创建iOS管理器(get、set、remove)KeyChain的本地方法。
- 创建 iOS 创建 UUID 的本机方法。
- 让 Cordova 使用本机方法:http://cordova.apache.org/docs/en/2.5.0/guide_plugin-development_ios_index.md.html
如果你不想自己做,使用我找到的插件: http://plugins.cordova.io/#/package/com.crypho.plugins.securestorage 要么 http://plugins.cordova.io/#/package/com.shazron.cordova.plugin.keychainutil
但是你应该检查它们是否正常工作。
Reming Hsu 保存任何 UDID 的想法是正确的,即使它是用于钥匙串中的应用程序然后重用它非常有效,这是完整的代码
NSString *myUUID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"myApp" accessGroup:nil];
if ([[keychainItem objectForKey:(__bridge id)kSecAttrAccount] length]) {
NSString *imeiFromK = [keychainItem objectForKey:(__bridge id)(kSecAttrAccount)];
}
else {
[keychainItem setObject:myUUID forKey:(__bridge id)(kSecAttrAccount)];
}