2

我正在使用此处找到的钥匙串包装器:

https://gist.github.com/1170641

像这样:

。H :

    #import "KeychainItemWrapper.h"

    KeychainItemWrapper *keychainItem;

米:

 keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"login" accessGroup:nil];

NSString *password = [keychainItem objectForKey:(__bridge id)kSecValueData];
NSString *username = [keychainItem objectForKey:(__bridge id)kSecAttrAccount];

然后它崩溃了:

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[_NSZeroData _fastCharacterContents]:无法识别的选择器发送到实例 0x14dcba60”

编辑:

由于回答了问题的用户,崩溃不再存在,但是当我检索用户名或密码时,它们有时会被交换,我的意思是 80% 的时间。

4

2 回答 2

3

Edit: I'm using kSecValueData but commented out //#define PASSWORD_USES_DATA in KeychainItemWrapper.m. Also I started using resetKeychainItem instead of trying to override the values myself.

Old Answer: I had this issue until I changed kSecValueData to kSecAttrService, which can be used for passwords also according to SecItem.h. Now everything seems to work fine (setting and retrieving).

于 2013-11-26T18:50:30.020 回答
1

我有一个类似的问题,我通过改变这个来解决它:

NSString *password = [keychainItem objectForKey:(__bridge id)kSecValueData];
NSString *username = [keychainItem objectForKey:(__bridge id)kSecAttrAccount];

对此:

NSString *password = [[NSString alloc] initWithData:[keychainItem objectForKey:(id)kSecValueData] encoding:NSUTF8StringEncoding];
NSString *username = [keychainItem objectForKey:(id)kSecAttrAccount];
于 2016-04-08T10:42:49.587 回答