如您所知,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