UIDevice uniqueIdentifier deprecated - What to do now?

后端 未结 30 2124
日久生厌
日久生厌 2020-11-21 06:07

It has just come to light that the UIDevice uniqueIdentifier property is deprecated in iOS 5 and unavailable in iOS 7 and above. No alternative method or pr

30条回答
  •  逝去的感伤
    2020-11-21 06:28

    We can use identifierForVendor for ios7,

    -(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.
    

提交回复
热议问题