38

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

John Topley
  • 113,588
  • 46
  • 195
  • 237
Oh Danny Boy
  • 4,857
  • 8
  • 56
  • 88
  • 2
    This isn't really an answer, but it is relevant to your question. Apple has is deprecating UDID access in iOS 5 http://techcrunch.com/2011/08/19/apple-ios-5-phasing-out-udid/ – Kye Aug 20 '11 at 01:00
  • 1
    @Kye : then How AdHoc & Push notifications can be performed , i m sure apple will have a way around for this! – Karthikeyan Aug 20 '11 at 09:51
  • 1
    @Karthikeyan - Push notifications do not use a UDID – radesix Jul 24 '12 at 06:46

10 Answers10

67

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.

Wolfram
  • 8,044
  • 3
  • 45
  • 66
Jacob Relkin
  • 161,348
  • 33
  • 346
  • 320
  • 18
    Note that this has been deprecated in [iOS 5](http://developer.apple.com/library/IOs/#documentation/UIKit/Reference/UIDevice_Class/DeprecationAppendix/AppendixADeprecatedAPI.html) – g_fred Nov 08 '11 at 14:07
  • Another good note is if you still want something similar to UDID that was not mentioned above look into retrieving the device's unique MAC address. – Albert Renshaw Sep 04 '13 at 16:48
  • @AlbertRenshaw: can you show me the solution get mac on ios 7, i just get mac address on ios 6. thanks – heaven Apr 17 '14 at 03:31
11

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!

Mohamed Jaleel Nazir
  • 5,776
  • 3
  • 34
  • 48
DZenBot
  • 4,806
  • 2
  • 25
  • 27
6

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);
Pierre de LESPINAY
  • 44,700
  • 57
  • 210
  • 307
ravinder521986
  • 722
  • 9
  • 17
  • 1
    it is very helpful for me very easy and it is used in ios5 or ios 6 – Jaspreet Singh Oct 17 '12 at 11:44
  • 8
    Please note that this is a generated id, so subsequent calls to `CFUUIDCreate` will create different ids. Typical pattern is: try to load ID from `NSUSerDefaults`, if `nil` then generate it with the code above and store it in `NSUserDefaults`. – Giacomo Jan 30 '13 at 09:54
  • 8
    It's worth repeating: this is not the UDID of the device - it's a generated UUID, and a new one is generated at every call. If you want a unique identifier, this method is okay. If you want **the UDID of the device** this is useless. – Abizern Feb 06 '13 at 12:24
3

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??

waza
  • 486
  • 9
  • 19
Miros
  • 527
  • 1
  • 3
  • 11
2

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.

Community
  • 1
  • 1
El Tomato
  • 6,479
  • 6
  • 46
  • 75
2

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.

Sunil Zalavadiya
  • 1,993
  • 25
  • 36
Tancrede Chazallet
  • 7,035
  • 6
  • 41
  • 62
  • 1
    While identifierForVendor does return a fixed UID on subsequent calls, it does not uniquely identify a device. It will change if you delete all that vendors apps and reinstall them. – Miros Sep 27 '13 at 08:59
2

Best way is to do it like this

NSString *udid = [[[UIDevice currentDevice]identifierForVendor]UUIDString];
Wesley Bland
  • 8,816
  • 3
  • 44
  • 59
user3711806
  • 161
  • 1
  • 7
  • This has already been suggested by [DZenBot](http://stackoverflow.com/a/12879212/1715579)'s and [Anc Ainu](http://stackoverflow.com/a/16144111/1715579)'s answers. – p.s.w.g Jun 09 '14 at 16:18
1

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

1

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

swathy krishnan
  • 916
  • 9
  • 22
0

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.

Femina
  • 1,239
  • 1
  • 12
  • 25