Hou*_*man 14 keychain ios keychainitemwrapper ios7
Apple已在其GenericKeyChain示例代码中提供了KeyChainItemWrapper类.在SO上有一个ARC'ed解决方案,我试图遵循:包装器存储在iOS上的KeyChain中.
包装器的用法如下:
KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"F11-email-auth" accessGroup:nil];
[keychain setObject:[emailTextfield text] forKey:(__bridge id)(kSecMatchEmailAddressIfPresent)];
[keychain setObject:[passwordTextfield text] forKey:(__bridge id)(kSecClassGenericPassword)];
Run Code Online (Sandbox Code Playgroud)
接受带有电子邮件文本字段的行.但是密码的第二行崩溃,出现以下异常.
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn't add the Keychain Item.'
*** First throw call stack:
(
0 CoreFoundation 0x01b445e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x018c78b6 objc_exception_throw + 44
2 CoreFoundation 0x01b44448 +[NSException raise:format:arguments:] + 136
3 Foundation 0x014a823e -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 Feeltracker 0x000053b3 -[KeychainItemWrapper writeToKeychain] + 899
5 Feeltracker 0x00004700 -[KeychainItemWrapper setObject:forKey:] + 272
6 Feeltracker 0x000092d6 -[FTLoginViewController connectToAccount:] + 374
7 libobjc.A.dylib 0x018d9874 -
Run Code Online (Sandbox Code Playgroud)
可能是什么原因?我想知道它是否与我正在使用的常数有关.
更新:
感谢rmaddy的帮助:
这似乎是错误的一点:
// No previous item found; add the new one.
result = SecItemAdd((__bridge CFDictionaryRef)[self dictionaryToSecItemFormat:keychainItemData], NULL);
NSAssert( result == noErr, @"Couldn't add the Keychain Item." );
Run Code Online (Sandbox Code Playgroud)
结果是-50.SecItemAdd是一个lib方法.正如我所料,这与KeyChain直接处理有某种关系......
keychainItemData包含:

Hou*_*man 15
我再也无法获得这个用于Keychain包装工作的Apple示例.幸运的是,对这个问题的进一步研究揭示了这个对我有用的解决方案.
请注意解决方案的原始答案不是ARC'ed,但是有人非常善于在Github上创建一个ARC'ed版本.我用过那个,就像一个魅力.
它是钥匙链的包装,比原来的更简单.
希望这有助于其他类似问题.
| 归档时间: |
|
| 查看次数: |
19578 次 |
| 最近记录: |