Search code examples
iosiphonecordovaphonegap-pluginscordova-plugins

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


Solution

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