Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS unique user identifier [duplicate]

I'm writting an application for iphone, which communicates with my server using REST. The main problem is, I need to identify user somehow. Not so long ago, we were allowed to use UDID, but now its not allowed anymore. So what should I use instead? I need some kind of identifier on iphone, so user will delete application, install it again, and he will get same id.

like image 452
Drabuna Avatar asked Sep 01 '11 15:09

Drabuna


People also ask

Is iOS UUID unique?

UUID (Universally Unique Identifier): A sequence of 128 bits that can guarantee uniqueness across space and time, defined by RFC 4122. UDID (Unique Device Identifier): A sequence of 40 hexadecimal characters that uniquely identify an iOS device (the device's Social Security Number, if you will).

How do I change my UDID on my iPhone?

You can't change the UUID of your iPhone. But Yes, you certainly can generate an alternative UUID. A guy Kind guy gekitz wrote a category on UIDevice which will generate some kind of UDID based on device mac-address and bundle identifier.

How do I find the UUID on my iPhone?

How to Find Your iPhone and iPad's UUID. Connect your iPhone or iPad to your computer, and then open iTunes. Click the device icon at the top. Your device's UUID is hidden by default—click “Serial Number” and it will change to display your UUID.


1 Answers

I used CFUUIDCreate() to create a UUID:

+ (NSString *)GetUUID {   CFUUIDRef theUUID = CFUUIDCreate(NULL);   CFStringRef string = CFUUIDCreateString(NULL, theUUID);   CFRelease(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.

like image 57
Moomio Avatar answered Sep 28 '22 12:09

Moomio