Created
February 14, 2014 14:15
-
-
Save Akii/9001694 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SERVER_NAME is a defined constant | |
// Create dictionary of search parameters | |
NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:(__bridge id)(kSecClassInternetPassword), kSecClass, SERVER_NAME, kSecAttrServer, kCFBooleanTrue, kSecReturnAttributes, nil]; | |
// Remove any old values from the keychain | |
OSStatus err = SecItemDelete((__bridge CFDictionaryRef) dict); | |
// Create dictionary of parameters to add | |
NSData* passwordData = [credentials.password dataUsingEncoding:NSUTF8StringEncoding]; | |
dict = [NSDictionary dictionaryWithObjectsAndKeys:(__bridge id)(kSecClassInternetPassword), kSecClass, SERVER_NAME, kSecAttrServer, passwordData, kSecValueData, credentials.username, kSecAttrAccount, nil]; | |
// Try to save to keychain | |
err = SecItemAdd((__bridge CFDictionaryRef) dict, NULL); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment