I am creating an iPhone and an accompanying iPad application that uses the Apple keychain shell class to store multiple session cookies (from Rails).
I am currently running applications on a simulator. If I enter one application, close and restart the simulator, it will load the cookies from the keychain correctly, and everything will be all right. And when I register the contents of keychain data, for example:
NSLog(@"Value for keychain data: %@, l: %d", [self.keychain objectForKey:(__bridge id)(kSecValueData)], [[self.keychain objectForKey:(__bridge id)(kSecValueData)] length]);
It correctly prints the contents of cookies.
However, if I then launched another application (after it was authenticated on the first one), it fails on line 305:
NSAssert( result == noErr, @"Couldn't add the Keychain Item." );
With this error in the output:
Assertion failure in -[KeychainItemWrapper writeToKeychain], /mydirectory/Classes/Models/Keychain/KeychainItemWrapper.m:305
And the NSLog data keychain says that it is completely empty.
The keyword identifier is unique for each application. I also looked at this thread - however, I set the access group to zero, and, more importantly, this comment in KeychainItemWrapper explains that this is still skipped in the simulator:
// Applications created for the simulator are not signed, so there is no keychain to test the simulator. This means that all applications can see all keychain elements when run on the simulator.
Thus, when looking at things, if I log in to the system in one application, I can leave and restart many times, and it loads fine. However, as soon as I log in to another one, the first application has a keychain for cleaning, so it goes to the login screen where you try to log in and load a new cookie, but then it crashes because it cannot add keychain element. The only way to fix this is with a reset simulator.