Peter Wilson
Peter Wilson

Reputation: 4319

Cordova-IOS How to get iPhone UUID or alternative identifier

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

Answers (3)

Reming Hsu
Reming Hsu

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?

More..

I am not working with Cordova, but i know how hybrid app working.

  1. Create iOS native method to manager(get、set、remove) KeyChain.
  2. Create iOS native method to create UUID.
  3. Let Cordova work with native method: http://cordova.apache.org/docs/en/2.5.0/guide_plugin-development_ios_index.md.html

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

Peter Wilson
Peter Wilson

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

Mark Veenstra
Mark Veenstra

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

Related Questions