如您所知,Apple最近弃用了UDID。所以我的解决方案,这是企业构建和UUID使用问题
- 生成CFUUID
- 将其保存到那里后,钥匙圈
- 重新访问钥匙串项目。
这一直工作良好。但是,由于某种原因,我们最近看到,在安装企业版本时,我们得到了一个不同的UUID(应该使用我们独特的访问密钥将其存储在钥匙串中)。
有没有人遇到过这种情况?下面是代码来创建UUID,并将其存储到钥匙扣..
+ (NSString *)registerUUIDWithKeyChain
{
CFUUIDRef udid = CFUUIDCreate(NULL);
NSString *uuidString = (NSString *) CFUUIDCreateString(NULL, udid);
KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"UniqueApp" accessGroup:nil];
NSString *userName = @"UniqueAppName";
NSString *password = uuidString;
[keychainItem setObject:userName forKey:(id)kSecAttrAccount];
[keychainItem setObject:password forKey:(id)kSecValueData];
[keychainItem release];
return uuidString;
}
+ (NSString *)userUUID
{
KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"UniqueApp" accessGroup:nil];
//Accesing the v_data was the only way. For some reason there is a runtime issue if we try to access it though "kSecValueData"
NSString *uuid = [keychainItem.keychainItemData objectForKey:@"v_Data"];
//Check if the app is installed for the first time on the device. If YES register the UUID in to the keychain.
//Also check if it is a reinstall by accessing the previous keyChainItem with our Identifier.
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"firstRun"] intValue] == 0 && !(uuid.length > 0))
{
uuid = [UIDevice_Additions registerUUIDWithKeyChain];
NSLog(@"\n First Time Registered UUID is %@", uuid);
//after stuff done
[[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithInt:1] forKey:@"firstRun"];
[[NSUserDefaults standardUserDefaults] synchronize];
[keychainItem release];
return uuid;
}
[keychainItem release];
return uuid;
}
@end
与CFUUID不同,CFUUID在每次调用时都会生成一个随机密钥,因此MAC地址与UUID具有相同的社会/道德问题。当MAC地址似乎也将以与UUID相同的方式被削减时,依靠可用的MAC地址是不安全的。 – 2012-04-26 00:59:19
这是一个Enterprise Build,他希望每次都保持UID相同,MAC地址不会像我们以前使用过的UUID那样改变(Apple不允许使用它) – adali 2012-04-26 01:11:12
ok,作为Enterprise Build,您可以使用UUID,** [[UIDevice currentDevice] uniqueIdentifier] ** – adali 2012-04-26 01:12:48