KeychainItemWrapper出现Couldn’t add/update the Keychain Item错误的解决方法

问题描述:使用 Apple 提供的 KeychainItemWrapper,出现了 Assertion 错误: Couldn't add the Keychain Item 或者 Couldn't update the Keychain Item。

问题分析:出现这一问题一般都是由于在一个文件中调用了两个或者两个以上的 keychain ,所以在 update 时候,会出现 kSecValueData 这个 key 的 value 出现重复,所以在 KeychainItemWrapper.m 中会出现
NSAssert( result == noErr, @"Couldn't update the Keychain Item." );

问题解决:setObject时候写一句:
[self.myKeychain setObject:@"YOUR_APP_INFO" forKey:(__bridge id)kSecAttrService];