Universally Unique Identifier in iOS 5

Apple is apparently starting to remove access to the UDID (Unique Device IDentifier) in iOS5. I’m not sure I agree that removing the UDID is completely necessary to protect user privacy, perhaps it’s one step too far, as it can prove useful for many reasons. In any event, the best you can now do for identification purposes is to use a UUID (Universally Unique IDentifier). This has to be on a per-app basis. That is, there is no way to identify the device any longer, but you can identify an app on a device. As long as the user doesn’t completely delete the app, then this identifier will persist between app launches, and at least let you identify the same user using a particular app on a device. Unfortunately, if the user completely deletes and then reinstalls the app then the ID will change, but this is the best anyone can do going forward.

Here is some code for a method that will let you create and use a UUID…

+ (NSString *)localUuid {
   NSString *ident = [[NSUserDefaults standardUserDefaults] objectForKey:@"unique identifier stored for app"];
   if (!ident) {
      CFUUIDRef uuidRef = CFUUIDCreate(NULL);
      CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef);
      CFRelease(uuidRef);
      ident = [NSString stringWithString:(NSString *)uuidStringRef];
      CFRelease(uuidStringRef);
      [[NSUserDefaults standardUserDefaults] setObject:ident forKey:@"unique identifier stored for app"];
      [[NSUserDefaults standardUserDefaults] synchronize];
   }
   return ident;
}

  • Pingback: Marek Bell » UDID and UUID alternative for iOS()

  • Thanks a lot for the info.

    I need a way to make sure the UUID does not change across an app uninstall/reinstall. I haven’t tried it yet, but it seems like you could do this by storing the UUID in the keychain. Only requires slightly more effort to store it there and then look for it before generating a new one. This type of storage should persist across app deletion / reinstall.