UIDevice uniqueIdentifier deprecated - What to do now?

后端 未结 30 2232
日久生厌
日久生厌 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-21 06:50

    Using the SSKeychain and code mentioned above. Here's code to copy/paste (add SSKeychain module):

    +(NSString *) getUUID {
    
    //Use the bundle name as the App identifier. No need to get the localized version.
    
    NSString *Appname = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];    
    
    //Check if we have UUID already
    
    NSString *retrieveuuid = [SSKeychain passwordForService:Appname account:@"user"];
    
    if (retrieveuuid == NULL)
    {
    
        //Create new key for this app/device
    
        CFUUIDRef newUniqueId = CFUUIDCreate(kCFAllocatorDefault);
    
        retrieveuuid = (__bridge_transfer NSString*)CFUUIDCreateString(kCFAllocatorDefault, newUniqueId);
    
        CFRelease(newUniqueId);
    
        //Save key to Keychain
        [SSKeychain setPassword:retrieveuuid forService:Appname account:@"user"];
    }
    
    return retrieveuuid;
    

    }

提交回复
热议问题