iOS unique user identifier

I used CFUUIDCreate() to create a UUID:

+ (NSString *)GetUUID {
  CFStringRef string = CFUUIDCreateString(NULL, theUUID);
  return [(NSString *)string autorelease];

Then set the above UUID to my NSString:

NSString *UUID = [nameofclasswhereGetUUIDclassmethodresides UUID];

I then stored that UUID to the Keychain using SSKeyChain

To set the UUID with SSKeyChain:

[SSKeychain setPassword:UUID forService:@"com.yourapp.yourcompany" account:@"user"];

To Retrieve it:

NSString *retrieveuuid = [SSKeychain passwordForService:@"com.yourapp.yourcompany" account:@"user"];

When you set the UUID to the Keychain, it will persist even if the user completely uninstalls the App and then installs it again.

To make sure ALL devices have the same UUID in the Keychain.

  1. Setup your app to use iCloud.
  2. Save the UUID that is in the Keychain to NSUserDefaults as well.
  3. Pass the UUID in NSUserDefaults to the Cloud with Key-Value Data Store.
  4. On App first run, Check if the Cloud Data is available and set the UUID in the Keychain on the New Device.

You now have a Unique Identifier that is persistent and shared/synced with all devices.

Firstly, the UDID is only deprecated in iOS 5. That doesn't mean it's gone (yet).

Secondly, you should ask yourself if you really need such a thing. What if the user gets a new device and installs your app on that? Same user, but the UDID has changed. Meanwhile, the original user might have sold his old device so now a completely new user installs your app and you think it's a different person based on the UDID.

If you don't need the UDID, use CFUUIDCreate() to create a unique ID and save it to the user defaults on the first launch (use CFUUIDCreateString() to convert the UUID to a string first). It will survive backups and restores and even come along with the original user when they switch to a new device. It's in many ways a better option that the UDID.

If you really need a unique device identifier (it doesn't sound like you do), go for the MAC address as pointed out in Suhail's answer.