Question

I was wondering if it was possible to find out the UDID of the user's iPhone. Can someone shed some light?

Was it helpful?

Solution

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.

OTHER TIPS

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!

In IOS5 and above, use this one to find UDID

NSString *uuidString = nil;
CFUUIDRef uuid = CFUUIDCreate(NULL);
if (uuid) {
    uuidString = (__bridge NSString *)CFUUIDCreateString(NULL, uuid);
    CFRelease(uuid);
}
NSLog(@"UDID: [%@]", uuidString);

It might be worth mentioning that the identifierForVendor is not unique for a device, it can and will eventually change.

Apple says this about identifierForVendor:

The value of this property is the same for apps that come from the same vendor running on the same device. A different value is returned for apps on the same device that come from different vendors, and for apps on different devices regardless of vendor.

If the value is nil, wait and get the value again later. This happens, for example, after the device has been restarted but before the user has unlocked the device.

The value in this property remains the same while the app (or another app from the same vendor) is installed on the iOS device. The value changes when the user deletes all of that vendor’s apps from the device and subsequently reinstalls one or more of them. The value can also change when installing test builds using Xcode or when installing an app on a device using ad-hoc distribution. Therefore, if your app stores the value of this property anywhere, you should gracefully handle situations where the identifier changes.

But what is even worse, is that it seems that Apple is also removing the last resort of using the MAC address as a Unique identifyer, according to this AVG Blog.

So what to do now, if we want to uniquely identify devices - eg. for licensing, settings or other purposes??

In IOS5 and above, use this one to find UDID

NSString *uuidString = nil;

CFUUIDRef uuid = CFUUIDCreate(NULL); ...

I think you are showing how to generate a unique identification number, not to get the unique id of a device.

I cannot comment, but I would like to warn others. In answer of DZenBot, all methods aren't giving the same results :


Alternative 1 (NSUUID class):

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

Alternative 2 (UIDevice class) (Available in iOS 6.0 and later):

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

Alternative 1 generate a random UUID while Alternative 2 give a fixed UID which won't change.

Best way is to do it like this

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

How about using [OpenUDID] lib https://github.com/ylechelle/OpenUDID

It's very simple. Go to Xcode Window and select Devices or you can find it in Organizer.enter image description here

http://www.raywenderlich.com/2915/ios-code-signing-under-the-hood/organizerudid

Remember UDID is deprecated in IOS 5. In iOS 7, Apple now always returns a fixed value when querying the MAC to specifically thwart the MAC as base for an ID scheme. So you now really should use -[UIDevice identifierForVendor] or create a per-install UUID. Hope it will help for someone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top