0

I am new to iOS. I need to create unique id from the device to register some of my web service for unique identification. There are lots of documents floating around the net, from which i noticed that retrieving UUID is deprecated in iOS6+.

I am targeting my application from iOS 5 +.

I had gone through the below link:

http://www.doubleencore.com/2013/04/unique-identifiers/

Three IDs are talked about. CFUUID, NSUUID, IDFV.

Given the scenario that i need to target from ios 5.0 which one i can use as a unique identifier ?

Kindly suggest.

Whoami
  • 13,930
  • 19
  • 84
  • 140
  • Rather than trying to identify a unique device you should be trying to identify a unique user so a user is not locked to a device. For this you should use a user ID/password combination and your secure web server. This will work across all iOS versions. – Robotic Cat Aug 28 '14 at 11:59
  • Thats true. But trying if i could manage with IDs. what if i keep CFUUID once generated and keep in the user default ? Only when it is reinstalled, i miss it , otherwise i can have it right ? – Whoami Aug 28 '14 at 12:00
  • This article may help you : http://nshipster.com/uuid-udid-unique-identifier/ – Zaphod Aug 28 '14 at 12:48
  • If you generate an `UUID` using `[NSUUID UUIDString]`, you could store this in iCloud and sync it between devices. This would get you a unique "user" but would only work if all your users log into iCloud. You would have to check (on launch) that the user is logged into iCloud and not allow full functionality until they have logged in. This is insecure as the user is never prompted for a password. There is a very, very, very, very tiny chance that UUIDs could be identical but it is infinitesimal. A `UID/PWD` is still the best way as you guarantee user uniqueness and security. – Robotic Cat Aug 28 '14 at 12:52

3 Answers3

0

Use this vendor id ( Identifier for Vendor (IDFV) ):

 NSString *aStrVendorId= [NSString stringWithFormat:@"%@", [[[UIDevice currentDevice]identifierForVendor] UUIDString]];
Yasika Patel
  • 6,356
  • 3
  • 19
  • 21
  • but IDFV is not available for ios5 – Whoami Aug 28 '14 at 11:59
  • Better you try first then comment bcz it is also working fine in ios 7. – Yasika Patel Aug 28 '14 at 12:41
  • @Templar I don't know why you are saying it is not working because it is working fine with IOS7 also I have used that. Maybe you are saying by just reading from github. – Rajesh Aug 28 '14 at 12:46
  • @Rajesh Yes, i said for that Github link. IDFV is available since ios6, OP clearly needs something which is available and usable through all iOS vesrions. – Templar Aug 28 '14 at 12:51
  • 1
    @Templar I have use UIDevice+IdentifierAddition from iOS5 to 7. Plz Better you try first then comment as Yasika said – Rajesh Aug 28 '14 at 12:54
  • 2
    @Rajesh Have you tried this on more than one device under iOS7? If you have you will find you always get same id as Apple doesn't return the real MAC address, they return a constant value – Paulw11 Aug 29 '14 at 08:02
  • @Paulw11 no i haven't used that in multiple device but i have checked after you mention that and yes it is giving same id in all IOS 7 device. Thanks for informing about that. – Rajesh Aug 29 '14 at 08:16
0

Why don't you just create a new UUID at install and store that in keychain/userdefaults ?

Is it really necessary that this UUID to be the same as the device's UUID ?

More details in this question.

Edit : this is the important part from there :

+ (NSString *)GetUUID
{
  CFUUIDRef theUUID = CFUUIDCreate(NULL);
  CFStringRef string = CFUUIDCreateString(NULL, theUUID);
  CFRelease(theUUID);
  return (__bridge NSString *)string;
}
Community
  • 1
  • 1
Templar
  • 1,694
  • 1
  • 14
  • 32
  • [[UIDevice currentDevice] uniqueIdentifier] (UUID) is now deprecated and apps are being rejected from the App Store for using it. – Yasika Patel Aug 28 '14 at 12:18
  • @Yasika Did you understand what i wrote above ? `CFUUID` is available and is NOT deprecated. Generate your own if you can't get one. It's that simple. – Templar Aug 28 '14 at 12:22
0

I've investigated a lot about this problem. The best solution i came up with is using IDFV + keychain

+(NSString*)deviceID{
KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"DeviceUDIDkeychain" accessGroup:nil];
NSString *devID = [keychain objectForKey:(__bridge id)(kSecAttrAccount)];
if (!devID || devID.length == 0) {
devID = [[[UIDevice currentDevice]identifierForVendor]UUIDString];
[keychain setObject:devID forKey:(__bridge id)(kSecAttrAccount)];
}
return devID;
}  
Timur Suleimanov
  • 435
  • 5
  • 16