Thursday 5 December 2013

The unique identifier in iOS App. "UDID" is replaced in ios 7 with "identifierForVendor"!

Sometimes in our app we need the unique key for identifying the device or user.

We can use UDID till iOS 6 and identifierForVendor for iOS 7 onwards.

    -(NSString*)uniqueIDForDevice
    {
        NSString* uniqueIdentifier = nil;
        if( [UIDevice instancesRespondToSelector:@selector(identifierForVendor)] ) {
             // >=iOS 7
            uniqueIdentifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
        }
        else {  //<=iOS6, Use UDID of Device     
                CFUUIDRef uuid = CFUUIDCreate(NULL);
                //uniqueIdentifier = ( NSString*)CFUUIDCreateString(NULL, uuid);- for non- ARC
                uniqueIdentifier = ( NSString*)CFBridgingRelease(CFUUIDCreateString(NULL, uuid));// for ARC
                CFRelease(uuid);
             }
        }
    return uniqueIdentifier;
    }



Important Note ---

UDID and identifierForVendor are different:---     

  •     1.) On uninstalling  and reinstalling the app identifierForVendor will change.   
  •     2.) The value of identifierForVendor remains the same for all the apps installed from the same vendor on the device.
  •     3.) The value of identifierForVendor also changes for all the apps if any of the app (from same vendor) is reinstalled.

No comments:

Post a Comment