So I created a work around, but I am sure there are better solutions out there.
I created a method that would turn a NSDictionary into a JSON String, and inserted the JSON String into the keychain password, that way you could store multiple values security.
NSDictionary *secretValues = [[NSDictionary alloc] initWithObjectsAndKeys:
password, @"password",
access_token, @"access_token",
refresh_token, @"refresh_token", nil];
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:secretValues
options:0
error:&error];
if (! jsonData) {
NSLog(@"Got an error: %@", error);
} else {
NSString *jsonString = [[NSString alloc] initWithData:jsonData
encoding:NSUTF8StringEncoding];
[keychainItem setObject:jsonString forKey:(__bridge id)(kSecValueData)];
}
Then if you want to get the password, you could do something like this:
- (NSString *) getPassword{
KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"com.myname.app" accessGroup:nil];
NSString *password = [[NSString alloc] initWithData:[keychainItem objectForKey:(__bridge id)(kSecValueData)]
encoding:NSUTF8StringEncoding];
NSDictionary *jsonData =
[NSJSONSerialization JSONObjectWithData: [password dataUsingEncoding:NSUTF8StringEncoding]
options: NSJSONReadingMutableContainers
error: nil];
return jsonData[@"password"];
}
I am sure a better way exists, but this was the best I could come up with.