3

我想在钥匙串中存储用户名和密码并通过警报视图验证它们。有没有人有代码?

我这样做是因为这些应用程序是内部的,我希望我的应用程序被应用程序商店接受。

4

1 回答 1

3
NSString *username = @"yourUserName";
NSString *password = @"yourPassword";
KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"TestAppLoginData" accessGroup:nil];

// Store username to keychain
[keychain setObject:username forKey:(id)kSecAttrAccount];

// Store password to keychain
[keychain setObject:password forKey:(id)kSecValueData]; 


// Get username from keychain (if it exists)
NSString *username = [keychain objectForKey:(id)kSecAttrAccount];
NSLog(@"username: %@", username);


// Get password from keychain (if it exists)  
NSString *password = [keychain objectForKey:(id)kSecValueData];
NSLog(@"password: %@", password);

在此处下载KeychainItemWrapper表格

于 2012-12-20T16:24:39.820 回答