1
votes

I have been trying to add keys to the keychain in iOS 8. I have tried the example: https://developer.apple.com/library/mac/documentation/security/conceptual/keychainServConcepts/iPhoneTasks/iPhoneTasks.html#//apple_ref/doc/uid/TP30000897-CH208-SW3 and using various libraries including: JNKeychain. With JNKeychain, the following code produces a null result:

- (IBAction)btnClick:(id)sender {
    [JNKeychain saveValue:@"[email protected]" forKey:(__bridge NSString*)(kSecAttrAccount)];
    NSData *data = [JNKeychain loadValueForKey:(__bridge NSString*)(kSecAttrAccount)];
    NSString *email = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSLog(@"Email: %@", email);
}

I was expecting that this code would return "Email: [email protected]". Can anyone help me figure out what I'm doing wrong?

1

1 Answers

2
votes

In iOS8 SecItemAdd and SecItemCopyMatching returns error code -34018(entitlements not found) .To solve this problem you have to turn on the “Keychain Sharing” in Capabilities tab.

Go to Target -> Capabilities -> turn on the “Keychain Sharing”

than clean, build and run again.