2

I am trying to uniquely identify the iPhone/iPad mobile devices to save user data.

I found out some, including

[NSString *UUID = [[NSUUID UUID] UUIDString];
[UIDevice currentDevice].identifierForVendor.UUIDString;

or take device token from

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{ ... }

But the problem is that

  1. UUID changes everytime I close and restart the app (I experienced from debugging)
  2. identiferForVendor changes every time I delete and reinstall the app (or update the app)
  3. I used device token to uniquely identify device across version updates, reinstall, but I learnt that it can be changed, and I am experiencing it from my updates and debugging in xCode.

Since app store rejects using uniqueIdentifer, my question here is: Is there any way we can uniquely identify devices across any application updates, deletion, reinstallation?

Popeye
  • 11,839
  • 9
  • 58
  • 91
Nicholas
  • 169
  • 1
  • 4
  • 15
  • See my answer here http://stackoverflow.com/questions/24252954/ios-detect-whether-my-sdk-is-installed-on-another-apps-on-the-device/24596243#24596243 this might help you. – iphonic Jul 21 '14 at 08:28
  • possible duplicate of [What is a long-term method I can use to uniquely identify an iOS device?](http://stackoverflow.com/questions/10319275/what-is-a-long-term-method-i-can-use-to-uniquely-identify-an-ios-device) – rishi Jul 21 '14 at 09:19

4 Answers4

2

Use SSkeychain to store unique key permanently. Take 4 files from sskeychain folder from this github example into your project

then after use this code to get unique identifier.

-(NSString *)getUniqueDeviceIdentifierAsString
{

    NSString *appName=[[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleNameKey];

    NSString *strApplicationUUID = [SSKeychain passwordForService:appName account:@"incoding"];
    if (strApplicationUUID == nil)
    {
        strApplicationUUID  = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
        [SSKeychain setPassword:strApplicationUUID forService:appName account:@"incoding"];
    }


    return strApplicationUUID;
}

This identifier will not change after deleting and reinstalling app. I have used this and it is working perfect for me.

Max
  • 2,269
  • 4
  • 24
  • 49
  • Actually the identifier will change after delete and install the app, but as you save the old UUID, you retrieve that and hence the solution. Reading it first time "This identifier will not change after deleting and reinstalling app." confused me – Ashwin G Aug 10 '17 at 16:04
  • as in given code, it is saving data in device's keychain, which will store until its formatted, so you can get back that data with proper key combination. – Max Aug 10 '17 at 16:37
  • Actually KeyChain is also not an advisable solution to retain data, remember iOS 10.3 betas resulting in data cleared from KeyChain on App uninstall. DeviceCheck is an interesting option. – Ashwin G Aug 15 '17 at 18:57
  • Hey @max, is this solution still working for iPhone and implementable through react native? I never developed for iPhones, only android. – O_o Dec 09 '17 at 18:07
1

The closest thing I can think of is generating your own UUID and storing it in the device keychain.

By doing this, it will survive app deletion/reinstall, and if the user has enabled iCloud Keychain, it should also survive a device restore.

To make things easier, you can use a keychain wrapper among the many available as open source (one is here).

sergio
  • 68,819
  • 11
  • 102
  • 123
  • 3
    But it won't survive a phone restore. – Mundi Jul 21 '14 at 08:27
  • 2
    if the user is enabled iCloud Keychain, it will. But generally speaking you are right. I wonder if a device after a restore is the same device, though, from a philosophical point of view... :-) – sergio Jul 21 '14 at 08:31
  • @sergio: thanks for your answer. But can you please provide me more details? – Nicholas Jul 21 '14 at 08:40
1

There's a great posting about this.

http://www.doubleencore.com/2013/04/unique-identifiers/

Ryan
  • 4,799
  • 1
  • 29
  • 56
0

One creative method might be the possibility of (ab)using the MAC address of the wifi port.

Community
  • 1
  • 1
Mundi
  • 79,884
  • 17
  • 117
  • 140
  • 1
    that would be cool, but with iOS 8 MAC address will be random: http://appleinsider.com/articles/14/06/09/mac-address-randomization-joins-apples-heap-of-ios-8-privacy-improvements – sergio Jul 21 '14 at 08:26
  • Good catch - I was not aware of that. – Mundi Jul 21 '14 at 08:28