Fortunately Apple provides access to the local keychain on the device and furthermore they provide a sample code how this could be done, but it is not yet ARC-compatible. After some googling I found a "corrected" version on GitHub which I use now in my project.
Using this class storing something in the keychain is quite easy:
and so is reading it.KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"MyAppLogin" accessGroup:nil];[keychainItem setObject:@"Password" forKey:(__bridge id)(kSecValueData)];[keychainItem setObject:@"Username" forKey:(__bridge id)(kSecAttrAccount)];
If you don't need the information stored anymore or it is expired do some cleanupNSString *password = [keychainItem objectForKey:(__bridge id)(kSecValueData)];NSString *username = [keychainItem objectForKey:(__bridge id)(kSecAttrAccount)];
and that's all.[keychainItem resetKeychainItem];
No comments:
Post a Comment