我一直在使用SSKeychain开源库将数据安全地存储在我的 iOS 应用程序中。昨天,我遇到一个问题,当我从 iTunes 将我的应用程序从 v1.0 更新到 v2.0 时,SSKeychain 无法保留其数据。
UUID 生成代码:
- (NSString *)createNewUUID
{
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
return (__bridge NSString *)string;
}
在这里,我生成了一个唯一的设备字符串并使用keychain
来存储它,并且应用程序严重依赖于唯一的字符串/设备标识符,因为从 iOS5 到 iOS7,Apple 对 进行了很多转换Unique Device Identifier
,因为这些方法已被弃用。
Store & Retrive 的应对片段:
NSString *retrieveuuid = [SSKeychain passwordForService:@"com.name.appname" account:@"AppName"];
if (retrieveuuid == nil) {
NSString *uuid = [self createNewUUID];
//Store the password in Keychain
NSError *error = nil;
[SSKeychain setPassword:uuid forService:@"com.name.appname" account:@"AppName" error:&error];
if ([error code] == SSKeychainErrorNotFound) {
NSLog(@"ID not found");
}
}
那么,当应用程序从 Apple 更新时,这是钥匙串无法保留其值/标识符的东西,还是我在某个时候错过了。请帮助是否可以将标识符永久存储在设备中,与安装、卸载、重置和更新应用程序无关。
或者,是否有任何 API 可以在生成时为我提供相同的设备 ID/唯一字符串,因此需要存储唯一字符串?
注意:应用程序必须支持 iOS 4.3 及更高版本。