Reputation: 4319
I am working on a Cordova based application and I need to identify the device for security reasons before send any requests to the server side
But as you may know Apple now forbidden any way to identify the device .
I have tried many plugins but it seems working only on android , on IOS it just identify the app not the device I also tried native objective C code like
[[[UIDevice currentDevice] identifierForVendor] UUIDString]
but it also changed on removing the app and reinstall it
Any suggestion on how to identify the iPhone either with UDID or IMEI or any other alternative
Upvotes: 0
Views: 5518
Reputation: 2225
Keep identifierForVendor or custom UUID in KeyChain.
It won't change on removing the app and reinstall it.
See: How to preserve identifierForVendor in ios after uninstalling ios app on device?
I am not working with Cordova, but i know how hybrid app working.
If you don't want to do it yourself, use the plugins i found: http://plugins.cordova.io/#/package/com.crypho.plugins.securestorage or http://plugins.cordova.io/#/package/com.shazron.cordova.plugin.keychainutil
But you should check if they are working.
Upvotes: 1
Reputation: 4319
Reming Hsu was right the idea of saving any UDID even if it was for the app in the keychain then reuse it was very effective and here is the full code
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)];
}
Upvotes: 0
Reputation: 4739
Why not use the standard cordova-plugin-device
which has the device.uuid
method and works on Android and IOS?
See: https://github.com/apache/cordova-plugin-device#deviceuuid
Get the device's Universally Unique Identifier (UUID).
var string = device.uuid;
Upvotes: 0