How can I retrieve the UDID on iOS?

Like some said, in iOS5 this has been deprecated:

NSString *udid = [[UIDevice currentDevice] uniqueIdentifier];

Apple now has 3 APIs to get a UUID(Universally Unique Identifier) of the device:

Alternative 1 (NSUUID class):

NSString *udid = [[NSUUID UUID] UUIDString];

Alternative 2 (UIDevice class):

NSString *udid = [[[UIDevice currentDevice] identifierForVendor] UUIDString];

Alternative 3 (ASIdentifierManager class, requieres AdSupport framework):

NSUUID *UUID = [[ASIdentifierManager sharedManager] advertisingIdentifier];
NSString *udid = [UUID UUIDString];

But they are all alphanumeric, and a tipical device unique identifier is only digits. So thos 3 APIs are useless, and the old [[UIDevice currentDevice] uniqueIdentifier] still works in iOS6, but for how long?

If the "deprecated" warning bugs you, just add:

#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

Hope it helps!


Note: Apple will no longer accept apps that access the UDID of a device starting May 1, 2013.

Instead, you must use the new methods identifierForVendor and advertisingIdentifier in iOS 6+ for accessing this. See related post here for more detail.


Old way (deprecated and will result in App Store rejection)

NSString *udid = [[UIDevice currentDevice] uniqueIdentifier];

As of iOS7, the uniqueIdentifier property is no longer available.

See the UIDevice reference.