0

我在我的应用项目中使用 KeyChainItemWeapper.m 来保存昵称和密码。在 iOS7 中完美运行,但在 iOS 6.0、6.1 中它崩溃了。错误是:

*** Assertion failure in -[KeychainItemWrapper writeToKeychain], /Users/KeychainItemWrapper.m:328
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn't add the Keychain Item.'
*** First throw call stack:
(0x1ea2012 0x1c5ae7e 0x1ea1e78 0x1919665 0xe785a 0xe6bf0 0x1479b6 0x14848f 0x11bb0bc 0x1c6e705 0xdcb2c0 0xdcb258 0xe8c021 0xe8c57f 0xe8b6e8 0xdfacef 0xdfaf02 0xdd8d4a 0xdca698 0x2f77df9 0x2f77ad0 0x1e17bf5 0x1e17962 0x1e48bb6 0x1e47f44 0x1e47e1b 0x2f767e3 0x2f76668 0xdc7ffc 0x15270d 0x356d725 0x1)
libc++abi.dylib: terminate called throwing an exception

此代码在应用程序崩溃中:

KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"100PrimerosLogin" accessGroup:nil];
[keychain setObject:disp_pasa.token forKey:(__bridge id)(kSecValueData)];
[keychain setObject:nick forKey:(__bridge id)(kSecAttrAccount)];
[keychain setObject:(__bridge id)(kSecClassGenericPassword) forKey:(__bridge id)kSecClass];
[keychain setObject:(__bridge id)kSecAttrAccessibleAlwaysThisDeviceOnly forKey:(__bridge id)kSecAttrAccessible];

昵称是 iphone mac,密码是字母数字代码。

谢谢你的提前。

4

1 回答 1

0

当您需要将 Auth Token 保存在 Keychain 中时,请保存 kSecAttrService 键的值:如:

[keychain setObject:@"YourAppNameDecription" forKey: (__bridge id)kSecAttrService];

保存令牌和其他字段时,还要在钥匙串中添加保存上述值。

这将解决您的崩溃问题。

于 2014-09-02T07:56:46.190 回答