Tuesday, December 31, 2013

UDID equivalent in iOS

From iOS 5 and above Apple deprecated uniqueIdentifier (accessing UDID of iOS device) method, I hope for some sort of security reasons. In iOS 7, Apple removed uniqueIdentifier property itself. So apps that requires a user specific id so as to run needs an alternative, here is one alternative way to get a unique identifier called GUID.

GUID is an acronym for 'Globally Unique Identifier'. GUID is also known as UUIDs(Universally Unique Identifiers). It is a 128-bit integer number used to identify resources.

Below code snippet (method) will generate a GUID in objective C - ARC version, which can run in any of iOS deployment target

+ (NSString *)generateGUID
    CFUUIDRef uuid = CFUUIDCreate(NULL);
    CFStringRef uuidStr = CFUUIDCreateString(NULL, uuid);
    return (__bridge NSString *) uuidStr;

Additional available alternative properties:

From iOS 6.0 and above, identifierForVendor property is available. 

Pros and Cons:

GUID’s can be generated in offline.

       Each time when we try to invoke this method it will return a different unique key, which is based on some specific point of time.

For more information on UIDevice properties you can visit Apples developer document in the following url https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDevice_Class/Reference/UIDevice.html#//apple_ref/occ/instp/UIDevice/identifierForVendor


  1. What about iOS 7. How could we get UDID??

    1. In iOS 7, Apple removed uniqueIdentifier property itself. So there is no way you can fetch UDID of a iOS device from your code, so inevitably you have to go for some alternative uniqueID, GUID is one of the alternative so as to get uniqueID specific to a device,user and specific timestamp.
      You can use the "generateGUID" which I have written in this post, Only thing is you should invoke this method only once,say on first launch and save it in your userDefaults or write somewhere in your app specific disk for further usage.
      You have to invoke this method only once because this method returns a uniqueID each time when you invoke w.r.t. that specific timestamp.
      Hope this helps,, :)