1

Possible Duplicate:
Unique identifier for an iPhone app

We are building an IOS application that was intended to use the device's serial number as a unique identifier to identify if a device is licenced or not. But according to this the unique identifier is deprecated in iOS 5.

Is there any other identifier we could use to uniquely identify devices?

Community
  • 1
  • 1
Hassan Mokdad
  • 5,832
  • 18
  • 55
  • 90
  • and [this](http://stackoverflow.com/questions/11597100/uniquely-identifying-an-ios-user) – msk Aug 13 '12 at 08:21

4 Answers4

5

This is what I do, which is also Apple's suggestion

Do not use the uniqueIdentifier property. To create a unique identifier specific to your app, you can call the CFUUIDCreate function to create a UUID, and write it to the defaults database using the NSUserDefaults class.

- (NSString *)getUUID {
    NSString *string = [[NSUserDefaults standardUserDefaults] objectForKey:@"deviceUUID"];
    if (string == nil) {
        CFUUIDRef   uuid;
        CFStringRef uuidStr;

        uuid = CFUUIDCreate(NULL);
        uuidStr = CFUUIDCreateString(NULL, uuid);

        string = [NSString stringWithFormat:@"%@", uuidStr];
        [[NSUserDefaults standardUserDefaults] setObject:string forKey:@"deviceUUID"];
        [[NSUserDefaults standardUserDefaults] synchronize];

        CFRelease(uuidStr);
        CFRelease(uuid);
    }

    return string;
}
Sascha
  • 5,903
  • 3
  • 24
  • 20
  • I found an issue, like what if user uninstall app and reinstall again. Next time, application is creating a new UUID which is not getting authenticated which stored at server side. How to resolve this. – Mrunal Dec 12 '14 at 06:57
1

We tend to solve this with the cookies approach popularized on the web, where the same rule applies. Basically, your app should check for the existence of your cookie; if it's not there, ask the server for one and persist it locally. Then with every request, send along the identifier. It is the server's job to generate a sufficiently distinct identifier for each new device.

In this way, you can still track individual users, just not by knowing more about them than you need to.

Chris Trahey
  • 18,202
  • 1
  • 42
  • 55
  • why not create a unique id for the app and just use that as the user id? CFUUIDRef theUUID = CFUUIDCreate(kCFAllocatorDefault); – Pochi Aug 13 '12 at 08:38
  • I guess if you are willing to trust that that is truly globally unique, it's functionally the same. However, I would prefer let the server decide so that it can guarantee no collisions with other users of my app (perhaps including an auto-incrementing component in the GUID) – Chris Trahey Aug 13 '12 at 08:43
  • it is globaly unique, or at least the probabilities of 2 being alike are just toooooooooo low. check the code. it uses not only time in a high precision but it has other fields of how its built. and just saying cuz this is easier to implement and uses less resources. the only drawback is that if the user deletes the app then this id is lost. so you would have to send it back to the user if it happens. – Pochi Aug 13 '12 at 08:46
-2

I use this:

//create a 30 digits random alphanumeric string
NSString *symbols = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
NSMutableString *randStr = [NSMutableString stringWithCapacity: 30];
for (int i=0; i<30; i++) 
   [randStr appendFormat: @"%C", [symbols characterAtIndex: rand()%[symbols length]]];
NSLog(@"Pseudo UUID = %@", randStr);

The probability of getting duplicates is extra-minor.

John Smith
  • 2,012
  • 1
  • 21
  • 33
  • 2
    ...and is still several order of magnitudes greater than a proper UUID-implementation like CFUUID. Don't reinvent the wheel. –  Aug 16 '12 at 04:44
-3

You can use UDID to send server. its a Unique id for each device.like below and send this to the server.

NSString *udid=[[UIDevice currentDevice]uniqueIdentifier];
M.B
  • 885
  • 2
  • 15
  • 31
  • 1
    That method is deprecated, it should not be used in new apps. Consider using the `CFUUID` API to create your own UUID. – Jasarien Aug 13 '12 at 08:34
  • But its still work on IOS 4.0. and there no mention that the user using IOS 4 or 5 – M.B Aug 13 '12 at 09:03