Nicholas
Nicholas

Reputation: 169

How can I uniquely identify iPhone/iPad?

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?

Upvotes: 2

Views: 2354

Answers (4)

Ryan
Ryan

Reputation: 4884

There's a great posting about this.

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

Upvotes: 1

sergio
sergio

Reputation: 69027

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).

Upvotes: 1

Max
Max

Reputation: 2299

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.

Upvotes: 2

Mundi
Mundi

Reputation: 80265

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

Upvotes: 0

Related Questions