2

I am using the KeychainItemWrapper to store my logged in users email and password. With the following code:

                    KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"loginData" accessGroup:nil];
                [keychainItem setObject:@"myString" forKey: (id)kSecAttrService];
                [keychainItem setObject:email forKey:(id)kSecAttrAccount];
                [keychainItem setObject:password forKey:(id)kSecValueData];

I get the following error:

*** Assertion failure in -[KeychainItemWrapper writeToKeychain], 

If I change this line:

[keychainItem setObject:email forKey:(id)kSecAttrAccount];

To this:

[keychainItem setObject:@"whatever" forKey:(id)kSecAttrAccount];

It works. So it seems that I can't set an email to the Keychain. What should I do?

el-flor
  • 1,466
  • 3
  • 18
  • 39
  • What type is `email`? When looking at the documentation, it should be a string. Based on this line of comment: [KeychainItemWrapper](https://gist.github.com/dhoerl/1170641#file-keychainitemwrapper-m-L70) – jbehrens94 Jan 06 '16 at 09:53
  • (NSString *)email it's a string indeed! – el-flor Jan 06 '16 at 10:16
  • The weird thing is, the documentation doesn't throw the error you're seeing. Could you link to the Github repo you're using KeychainItemWrapper from? Or is that a native class? – jbehrens94 Jan 06 '16 at 10:36
  • https://gist.github.com/dhoerl/1170641 I'm using this one. Should I use another one? – el-flor Jan 06 '16 at 10:36
  • Try changing `forKey:(id)kSecAttrAccount` to `forKey:(__bridge id):kSecAttrAccount`, that might work. If it doesn't, set a breakpoint at that line (`keychainItem setObject:email...`) and please show what the debug console tells you. – jbehrens94 Jan 06 '16 at 10:43
  • It doesn't work sadly. It only shows the error I put above... ```*** Assertion failure in -[KeychainItemWrapper writeToKeychain], ``` What is the way to go? – el-flor Jan 06 '16 at 14:53

0 Answers0