Ios5 iOS在密钥链中保存多个密码

Ios5 iOS在密钥链中保存多个密码,ios5,keychain,Ios5,Keychain,我想在我的钥匙链中保存两个密码(一个应用程序pin和一个后端pin),我想知道这应该如何工作。 我正在使用KeychainItemWrapper,它具有不同的标识符 KeychainItemWrapper *kcw1 = [[KeychainItemWrapper alloc] initWithIdentifier:id1 accessGroup:nil]; KeychainItemWrapper *kcw2 = [[KeychainItemWrapper alloc] initWithIden

我想在我的钥匙链中保存两个密码(一个应用程序pin和一个后端pin),我想知道这应该如何工作。
我正在使用KeychainItemWrapper,它具有不同的标识符

KeychainItemWrapper *kcw1 = [[KeychainItemWrapper alloc] initWithIdentifier:id1 accessGroup:nil];
KeychainItemWrapper *kcw2 = [[KeychainItemWrapper alloc] initWithIdentifier:id2 accessGroup:nil];
我使用其中一个来保存和检索应用程序或后端pin

我使用:

[self.kcw1 setObject:aVerifyCode forKey:(__bridge id) kSecValueData]
[self.kcw2 setObject:aAppPin forKey:(__bridge id) kSecValueData]
但它不起作用-结果是-25299-指定的项已存在于密钥链中


那么如何在钥匙链中保存多个密码呢?

好的,我想我知道问题出在哪里了! KeychainItemWrapper使用kSecAttrGeneric的标识符。
但这不是区分条目的方法。如果要在中保存两个帐户或两个密码

kSecValueData

这将导致重复实体的arror(-25299)。
原因是,apple keychain api使用

kSecAttrAccount

kSecAttrService

区分条目。

因此,如果需要,可以修改KeychainItemWrapper,如图所示