0

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

Peter Wilson
  • 4,150
  • 3
  • 35
  • 62
  • 2
    It is not possible to read the original UUID from iOS devices. – Joerg Jun 04 '15 at 08:57
  • The point mentioned by Joerg is very important. You can no longer get a specific device identifier which is persistent across reinstalls and different apps. You have to use the vendor identifier which *can* be changed by the user. You should not try to find a way to get something like a real UUID because that would violence your users privacy. If Apple would notice, you would probably even be kicked out of app store. – iCaramba Jun 04 '15 at 11:45
  • Try this https://github.com/apache/cordova-plugin-device#deviceuuid – Vishal Singh Jun 04 '15 at 13:56

3 Answers3

1

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.

Community
  • 1
  • 1
Reming Hsu
  • 2,215
  • 15
  • 18
0

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;

Community
  • 1
  • 1
Mark Veenstra
  • 4,691
  • 6
  • 35
  • 66
  • 1
    it also returns an unique identifier per application not per device which mean when user remove the app and install it again it generate another UUID – Peter Wilson Jun 04 '15 at 08:34
0

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)];


}
Community
  • 1
  • 1
Peter Wilson
  • 4,150
  • 3
  • 35
  • 62