我正在使用 Apple 示例代码提供的 KeyChainItemWrapper 类将身份验证 token 保存到钥匙串(keychain)。
KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier"JetTaxiApp_AuthToken" accessGroup:nil];
但是当我尝试将值设置为钥匙串(keychain)时,出现了一个奇怪的异常
[_authenticationTokenKeychain setObject:authenticationToken forKey: @"auth_token"];
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn't add the Keychain Item.'
钥匙串(keychain)还不存在(在调用时) 什么会导致此异常?
最佳答案
您需要使用标准 key ,所以这里您的 @"auth_token"
不正确。
The keys that can be used for this purpose and the possible values for each key are listed in the “Keychain Services Constants” section.
来源,包含有效常量列表:Keychain Services Reference
例如,您可以使用:
[_authenticationTokenKeychain setObject:authenticationToken forKey: (__bridge NSString *)kSecValueData];
关于iphone - 使用 KeyChainItemWrapper 在 KeyChain 中存储 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7117885/