I'm building an iPhone and an accompanying iPad application that is using Apple's keychain wrapper class to store multiple session cookies (from Rails).
I am currently running the apps on the simulator. If I login on one app, quit and relaunch simulator, it loads the cookies from keychain correctly and all is fine. And when I log the contents of the keychain data like so:
NSLog(@"Value for keychain data: %@, l: %d", [self.keychain objectForKey:(__bridge id)(kSecValueData)], [[self.keychain objectForKey:(__bridge id)(kSecValueData)] length]);
It prints out the contents of the cookies correctly.
However, if I then launch the other app (after having authenticated on the first), then it crashes at line 305:
NSAssert( result == noErr, @"Couldn't add the Keychain Item." );
With this error in output:
Assertion failure in -[KeychainItemWrapper writeToKeychain], /mydirectory/Classes/Models/Keychain/KeychainItemWrapper.m:305
And the NSLog of the keychain data says that it is entirely empty.
The keychain identifier is unique for each app. I also looked at this thread - however I have set the access group to nil, and more importantly this comment in the KeychainItemWrapper explains that in the simulator this is skipped anyway:
// Apps that are built for the simulator aren't signed, so there's no keychain access group for the simulator to check. This means that all apps can see all keychain items when run on the simulator.
So by the looks of things, if I login onto one app, I can quit and relaunch many times over and it loads perfectly. However once I log onto the other, the first app has it's keychain wiped, so it goes to login screen where you attempt to login and fetch a new cookie, but then crashes because it can't add the keychain item. The only way to fix it is to Reset the simulator.