简体   繁体   English

iOS6中的KeychainItemWrapper

[英]KeychainItemWrapper in iOS6

I'm using KeyChainItemWeapper.m in my app project to save the nickname and the password. 我在我的应用程序项目中使用KeyChainItemWeapper.m来保存昵称和密码。 In iOS7 works perfectly but in iOS 6.0, 6.1 it crashes. 在iOS7中可以完美运行,但在iOS 6.0、6.1中会崩溃。 The error is: 错误是:

*** 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

This code is on the app crash: 此代码在应用程序崩溃时:

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];

The nickname is the iphone mac and the password an alphanumeric code. 昵称是iphone mac,密码是字母数字代码。

Thank you for advance. 谢谢您的提前。

When you need to save the Auth Token in Keychain, then save the value for kSecAttrService key: like: 当您需要将认证令牌保存在钥匙串中时,然后保存kSecAttrService密钥的值:

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

Add save above value also in keychain when saving token and other fields. 保存令牌和其他字段时,也要在钥匙串中添加高于值的保存。

This will resolves your crashing issue. 这样可以解决您的当机问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM