2

我正在使用钥匙串包装器(在另一个线程上推荐)

https://gist.github.com/1170641

导致错误的代码:

//Save username + password to keychain
KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc]     initWithIdentifier:@"PHP POS" accessGroup:nil];

[keychainItem setObject:username forKey:@"username"];
[keychainItem setObject:password forKey:@"password"];

例外:

2013-01-28 14:51:09.531 PHP POS[21078:c07] *** Assertion failure in -[KeychainItemWrapper writeToKeychain], /Users/cmuench/Desktop/PHP-Point-Of-Sale-Repos/PHP-Point-Of-Sale-iOS/KeychainWrapper/KeychainItemWrapper.m:305
2013-01-28 14:51:09.532 PHP POS[21078:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn't add the Keychain Item.'
*** First throw call stack:
(0x13be012 0x1186e7e 0x13bde78 0xc1cf35 0x233e4 0x22859 0x34ec 0x4ef0 0x48e2 0x19f37b 0x1a8048 0x24c9bf 0x2534df 0x252fec 0x251f5e 0x25c076 0xdf43b 0x1dce05 0x1dce05 0x1dce05 0x1dce05 0xdf495 0xdee66 0xdf24b 0xd0cf8 0x225fdf9 0x225fad0 0x1333bf5 0x1333962 0x1364bb6 0x1363f44 0x1363e1b 0x225e7e3 0x225e668 0xce65c 0x255d 0x2485)
libc++abi.dylib: terminate called throwing an exception

注意:我在模拟器中运行它。

4

2 回答 2

3

您的问题是 @"username" 和 @"password" 不是有效的键值。

您必须使用Keychain Services Reference中的一个。

于 2013-03-22T19:33:49.973 回答
0

该代码不起作用,它会遇到我问这个问题时遇到的相同问题。查看我找到的答案和 ARCified 我的答案的另一个答案,它应该可以帮助你。

于 2013-01-28T20:01:13.067 回答