16

I have using the following code for get identifier

        deviceName = [[UIDevice currentDevice]uniqueIdentifier];

But i got the warning uniqueIdentifier is deprecated in ios5.

so how to get the identifier value in ios5?

  • possible duplicate of [UIDevice uniqueIdentifier Deprecated - What To Do Now?](http://stackoverflow.com/questions/6993325/uidevice-uniqueidentifier-deprecated-what-to-do-now) – Thomas Clayson Sep 26 '12 at 10:30

4 Answers4

18

You can use the following code

if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
    // This will run if it is iOS6 or higher
    return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
} else {
   // This will run before iOS6 and you can use openUDID or other 
   // method to generate an identifier
}

And this way you can maintain the previous min requirement.

This identifier is unique for all the apps from one vendor. If you want unique identifier for device you need to use:

if (!NSClassFromString(@"ASIdentifierManager")) {
    // This will run before iOS6 and you can use openUDID, per example...
    return [OpenUDID value];
}
return [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];

Warning: There is a bug on iOS6 that reports "null" identifier if the device was updated "by air" - More info

Community
  • 1
  • 1
J. Costa
  • 7,442
  • 4
  • 26
  • 31
1

You can't get UUID anymore. It is forbidden to do so, your app will be rejected by Apple.

Ivor Prebeg
  • 988
  • 6
  • 11
1

in ios 7 you better use [UIDevice identifierForVendor] or you run into trouble, because only a fake MAC gets returned.

Karsten
  • 1,869
  • 22
  • 38
0

The method demonstrated by J.Costa is the good one for iOS 6.

But if you want to keep the same identifier in your app when your user upgrade his phone, or within your several apps (Unless they share the same Bundle Seed ID), use this : https://github.com/blackpixel/BPXLUUIDHandler

Very useful!

iGranDav
  • 2,450
  • 1
  • 21
  • 25
  • BPXLUUIDHandler's call to `return [[UIDevice currentDevice] uniqueIdentifier];` will fail on an iPhone 5 simulator (so I'm not sure what the reason is for guarding on TARGET_IPHONE_SIMULATOR). BPXLUUIDHandler is missing proper key chain constants.... The UDID might show up on a Mac or PC via iTunes, or in Apple's cloud. Developer driven security requirements really are the pits. – jww Nov 13 '12 at 23:45