iOS开发 获取设备UUID

方案1:

[[[UIDevice currentDevice] identifierForVendor] UUIDString]

方案2:

-(NSString*)getDeviceId{
    NSString* uuidString = nil;
    if (![[NSUserDefaults standardUserDefaults] objectForKey:@"deviceId"]) {

        CFUUIDRef uuidRef = CFUUIDCreate(kCFAllocatorDefault);
        CFStringRef strRef = CFUUIDCreateString(kCFAllocatorDefault, uuidRef);
        uuidString = [NSString stringWithString:(__bridge NSString*)strRef];

        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setValue:uuidString forKey:@"deviceId"];
        [defaults synchronize];

        CFRelease(strRef);
        CFRelease(uuidRef);
    }else{
        uuidString = [[NSUserDefaults standardUserDefaults] objectForKey:@"deviceId"];
    }

    return uuidString;
}

具体2个方案,获取的UUID不一样,具体干嘛的,暂时也不太了解,反正项目中说要获取唯一ID,但是苹果现在严格限制获取UUID,不知道审核中能否通过,方案1,有人试过说没有问题,具体是否应该使用,还望慎用。

你可能感兴趣的:(ios开发)