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);
    CFRelease(uuid);
    return (__bridge NSString *) uuidStr;
}

Additional available alternative properties:

From iOS 6.0 and above, identifierForVendor property is available. 

Pros and Cons:

Pros:
GUID’s can be generated in offline.

Cons:
       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