Iphone 使用KeyChainItemWrapper在KeyChain中存储密钥
我使用的是KeyChainItemWrapper类,由Apple的示例代码提供,用于将身份验证令牌保存到keychainIphone 使用KeyChainItemWrapper在KeyChain中存储密钥,iphone,objective-c,keychain,xcode,Iphone,Objective C,Keychain,Xcode,我使用的是KeyChainItemWrapper类,由Apple的示例代码提供,用于将身份验证令牌保存到keychain KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier"JetTaxiApp_AuthToken" accessGroup:nil]; 但当我试图将值设置为keychain时,会出现一个奇怪的异常 [_authenticationTokenKeychain setOb
KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier"JetTaxiApp_AuthToken" accessGroup:nil];
但当我试图将值设置为keychain时,会出现一个奇怪的异常
[_authenticationTokenKeychain setObject:authenticationToken forKey: @"auth_token"];
由于未捕获异常而终止应用程序
“NSInternalInconsistencyException”,原因:“无法添加密钥链。”
项目。”
钥匙链还不存在(在此调用时)
什么会导致此异常?您需要使用标准密钥,因此您的
@“身份验证令牌”
不正确
“Keychain Services Constants”(钥匙链服务常量)部分列出了可用于此目的的钥匙以及每个钥匙的可能值
源,包含有效常量的列表:
例如,您可以使用:
[\u authenticationTokenKeychain setObject:authenticationToken forKey:(\u bridge NSString*)kSecValueData]
对于上面的代码段,key param只能使用sdk提供的密钥。
您可以在SecItem.h中找到all确保添加了keychain access plist文件。看看在使用ARC版本的keychainItemWrapper时,您需要按照以下方式执行:
[\u authenticationTokenKeychain setValue:authenticationToken forKey:(\u bridge NSString*)kSecValueData]代码>@DamienMATHIEU我正在使用ARC版本,但仍然有问题。我收到以下错误:“[setValue:forUndefinedKey:]:该类不符合密钥v_数据的键值编码要求。“知道可能有什么问题吗?@Intervector使用setValue而不是setValue,请使用setObject。”
[_authenticationTokenKeychain setObject:authenticationToken forKey: @"auth_token"];