19
votes

What is the best way to uniquely register an iOS Device, which won't be limited by future Apple restrictions?

My current approach to register an iOS device (basically to identify the device uniquely) is that I use the UDID of an iOS device to identify it and register it, and then after recognising it I perform the necessary actions.

The issue is that the UIDevice uniqueIdentifier property is deprecated. There are certain workarounds for that (as discussed in this question) which I'm aware of.

One possibility is to use the MAC address of an iOS device. However, I feel that Apple may restrict access to this information at some point in the future, as well.

Is there any other way (besides accessing the MAC address) to identify an iOS device, which we can rely on for the future?

5
@KyleJones - not exactly dupe of the question mentioned by you, i have already given reference of that. In that question it is suggested to use Mac Address of iOS device, which i had already mentioned. I know that but i don't want to rely on that. coz after sometime apple might restrict access of that.rishi
It's not a great answer, but you could ask permission to push and get the device token? That has to be unique to the device, and some variant of this will be around as long as APN stays around.danh

5 Answers

7
votes

Using Apple's preferred method of generating a CFUUIDRef is probably the better solution as I feel the MAC address may be removed in the future as well. If you use this and save it to your NSUserdefaults you will have it persist unless the user deletes the app. If you want to have a generated unique ID that you can share between apps or persist between installs you should look at using the UIPasteboard and saving your generated UID with a key that you share between apps.

//Create a unique id as a string
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);

//create a new pasteboard with a unique identifier
UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:@"youruniquestring" create:YES];

[pasteboard setPersistent:YES];

//save the unique identifier string that we created earlier
[pasteboard setString:((__bridge NSString*)string)];


 //accessing it
UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:@"youruniquestring" create:NO];
NSLog([pasteboard string]);

I have written a brief tutorial here but its basically the lines above: http://www.roostersoftstudios.com/2012/03/26/a-way-to-share-data-between-apps-on-a-given-ios-device/

4
votes

Unless your application is for managing my Apple devices, it is the wrong approach. As a user, I don't want you to know which device I'm using. I want you to recognize me, whatever the device I use. I want to be able to replace a defective device. Apple will restrict more and more the access to this information.

[edit] I can't see how a MAC address could work. My iOS devices can have multiple.

2
votes

Another option is dynamically generating your own UUID.

CFUUIDRef uuid = CFUUIDCreate(NULL); 
CFStringRef generatedUuidStr = CFUUIDCreateString(NULL, uuid);
CFRelease(uuid);
NSString* uuidStr = [(NSString*)generatedUuidStr autorelease];

You could persist this UUID in NSUserDefaults for install based uniqueness. If device based uniqueness is truly the most important thing (so that after an uninstall and reinstall the id persists) you'll need a mechanism to persist the ID on the device. I think you could look into using the Keychain in order to persist that ID which should persist beyond app uninstall. You can even use an access group when adding the UUID to the keychain so that you could have a suite of apps that use the same UUID.

See apple's security framework reference for more info on saving keychain items and retrieving them.

http://developer.apple.com/library/ios/#DOCUMENTATION/Security/Reference/SecurityFrameworkReference/_index.html

1
votes

The best approach I've seen is using the keychain. You can generate an UUID with the CFUUIDCreateString function and store it in the keychain. This data stays in the device between installs and restores from backups.

-2
votes

Use the devices Mac address. It's as unique as you could need I think.

How can I programmatically get the MAC address of an iphone