Search code examples
icloududid

Unique identifier associated to the iCloud account


I would like to use a code to identify users, without asking them for their email address or other sensitive information, that would also possibly follow her when she changes device. Long ago I trustily implemented the following piece of code:

NSString *strApplicationUUID=nil;
+(NSString*) sharedUdid{
    if (!strApplicationUUID){
         NSString *appName=[[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleNameKey];
         strApplicationUUID = [SSKeychain passwordForService:appName account:@"incoding"];
        if (strApplicationUUID == nil) {
            strApplicationUUID=[[NSUserDefaults standardUserDefaults] objectForKey:@"udid"];
            if (!strApplicationUUID) strApplicationUUID=[[[UIDevice currentDevice] identifierForVendor] UUIDString];
            else strApplicationUUID  = [[NSUUID UUID] UUIDString];
           [SSKeychain setPassword:strApplicationUUID forService:appName account:@"incoding"];
        }

    }
    return strApplicationUUID;
}

That I unfortunately found producing all but unique identifiers for each user. So I temporarily switched to using the token, notwithstanding its length and the fact it is linked to a single device. Is there some better solution?


Solution

  • I switched to using the CloudKit identifier.