19

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?

Community
  • 1
  • 1
rishi
  • 11,779
  • 4
  • 40
  • 59
  • Dup of http://stackoverflow.com/questions/6993325/uidevice-uniqueidentifier-deprecated-what-to-do-now – Kyle Jones Apr 25 '12 at 16:02
  • 2
    @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 Apr 25 '12 at 16:05
  • 2
    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 Apr 25 '12 at 16:10

5 Answers5

7

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/

rooster117
  • 5,502
  • 1
  • 21
  • 19
  • It might be a better choice to use a Credential Store using the iOS keychain, e.g. you might use SSKeychain to interact with that. It seems more appropriate than using UIPasteboard which is usually for UI operations (like copy and paste) – Diego Jun 10 '13 at 12:49
4

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.

Stephan Eggermont
  • 15,847
  • 1
  • 38
  • 65
2

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

NSProgrammer
  • 2,387
  • 1
  • 24
  • 27
  • 2
    Ensure that you save the UUID created by these functions, because they will be DIFFERENT every time you call this function. This is not a drop-in replacement for uniqueIdentifier, but it may be good enough for you purposes. – Sam May 05 '12 at 23:58
  • Yes, I was implying that, but Sam said it explicitly. +1 to Sam for clarity. – NSProgrammer May 06 '12 at 04:24
  • @nob1984 - there is some pit holes in this as well, if user deleted the app and installs again, then also we will loose him. – rishi May 06 '12 at 17:32
  • @rishi This is only a problem if the UUID is stored somewhere locally (NSUserDefaults) and will be lost on uninstall. Otherwise the UUID can be retrieved when the user logs in successfully on the next install. – Sam May 06 '12 at 19:11
  • @rishi - yes, I mentioned that already as a drawback that Sam reiterated. The keychain storage method would be the way to handle persistence across uninstalls and reinstalls (which I also mentioned). – NSProgrammer May 06 '12 at 23:21
  • +1 for mentioning using keychain to persist generated ID during uninstalls and reinstalls. NSUserDefaults will be deleted during uninstalls and reinstalls. – Andreas Paulsson Feb 13 '13 at 13:04
1

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.

Javier C
  • 726
  • 5
  • 15
-2

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

Community
  • 1
  • 1
shein
  • 1,834
  • 15
  • 23
  • 1
    Oops sorry jumped the gun. But MAC address is unlikely to go away so soon since its part of a core framework used for all tcp/ip socket communication so it would be your safest bet. Do you need unique device or unique app installation? If you want unique installation you could always generate a unique ID on a server. But it will disappear once the app is uninstalled or device restored. – shein Apr 25 '12 at 16:45
  • might be access to mac address also can be restricted in some time. And as you say second option of device token on server is also not a very good option. – rishi Apr 25 '12 at 16:51
  • These are your only options. ANY unique device id Method COULD be restricted at some point.... MAC address at least has some more uses and is much less likely to be restricted. – shein Apr 25 '12 at 16:55
  • 1
    Don't use the MAC address. You'll be sorry when it's taken away. – james woodyatt Mar 23 '13 at 05:13
  • yes but by that logic ANYTHING can be taken away... so the alternative would be? – shein Mar 23 '13 at 20:08
  • Well I'll be the first to eat my hat here. 1 year later and MAC address access was taken away... But Apple now provides identifierForVendor method – shein Jun 16 '13 at 06:16