谢谢大家的答案。
这是我使用的解决方案:
将文件 KeychainItemWrapper.h/m 添加到我的项目中
分配 2 个钥匙串项目:
//aloc for user password
keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"passowrdKey1" accessGroup:nil];
//aloc for user password2
keychainItem2 = [[KeychainItemWrapper alloc] initWithIdentifier:@"passowrdKey1" accessGroup:nil];
然后就用它来读/写
//WRITE
// save password
[keychainItem setObject:@"password1" forKey:(__bridge id)(kSecValueData)];
// save password2
[keychainItem2 setObject:@"password2" forKey:(__bridge id)(kSecValueData)];
//READ
//get pasword from keychain
NSString *_pass = [keychainItem objectForKey:(__bridge id)(kSecValueData)];
//get pasword from keychain
NSString *_pass2 = [keychainItem2 objectForKey:(__bridge id)(kSecValueData)];