2014-09-02 29 views
0

我在我的應用程序項目中使用KeyChainItemWeapper.m來保存暱稱和密碼。在iOS7中完美工作,但在iOS 6.0中,6.1崩潰。錯誤是:iOS6中的KeychainItemWrapper

*** 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和密碼的字母數字代碼。

謝謝您的提前。

+0

可能的重複http://stackoverflow.com/questions/19749160/saving-in-keychainitemwrapper-crashes-for-password – Andrey 2014-09-02 07:51:45

回答

0

當你需要保存身份驗證令牌在鑰匙串,然後保存爲kSecAttrService鍵的值: 像:

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

添加除上文值也鑰匙扣節省令牌等領域時。

這將解決您的崩潰問題。

+0

謝謝你,它的工作原理。我試過了,但是我沒有把上面的值放在保存令牌上面。 – amurcia 2014-09-02 09:20:45