UIDevice uniqueIdentifier deprecated - What to do now?

Oliver Pearmain picture Oliver Pearmain · Aug 9, 2011 · Viewed 161.4k times · Source

It has just come to light that the UIDevice uniqueIdentifier property is deprecated in iOS 5 and unavailable in iOS 7 and above. No alternative method or property appears to be available or forthcoming.

Many of our existing apps are tightly dependent on this property for uniquely identifying a particular device. How might we handle this problem going forward?

The suggestion from the documentation in 2011-2012 was:

Special Considerations

Do not use the uniqueIdentifier property. To create a unique identifier specific to your app, you can call the CFUUIDCreate function to create a UUID, and write it to the defaults database using the NSUserDefaults class.

However this value won't be the same if a user uninstalls and re-installs the app.

Answer

DarkDust picture DarkDust · Aug 9, 2011

A UUID created by CFUUIDCreate is unique if a user uninstalls and re-installs the app: you will get a new one each time.

But you might want it to be not unique, i. e. it should stay the same when the user uninstalls and re-installs the app. This requires a bit of effort, since the most reliable per-device-identifier seems to be the MAC address. You could query the MAC and use that as UUID.

Edit: One needs to always query the MAC of the same interface, of course. I guess the best bet is with en0. The MAC is always present, even if the interface has no IP/is down.