直接贴代码
KeychainItemWrapper *keychain=[[KeychainItemWrapper alloc] initWithIdentifier:@"xxxxxx" accessGroup:nil];//xxxx 自定义
保存
[keyWrapper setObject:@"myChainValues" forKey:(id)kSecAttrService];
[keyWrapper setObject:[usernameTextField text] forKey:(id)kSecAttrAccount];// 上面两行用来标识一个Item
[keyWrapper setObject:[passwordTextField text] forKey:(id)kSecValueData];
读取
[usernameTextField setText:[keyWrapper objectForKey:(id)kSecAttrAccount]];
[passwordTextField setText:[keyWrapper objectForKey:(id)kSecValueData]];
另外需要引入Security.framework 和KeychainItemWrapper头文件(百度一下多得是)