iOS keychain包装器NSInternalInconsitity Exception

时间:2013-01-28 19:54:03

标签: ios keychain

我正在使用钥匙串包装器(正如另一个线程所推荐的那样)

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

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

2 个答案:

答案 0 :(得分:3)

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

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

答案 1 :(得分:0)

该代码不起作用,它会遇到我在问this question时遇到的同样问题。看看我找到的答案和另一个答案谁给我答案,它应该帮助你。