after leading with a lot of problems with the class KeychainItemWrapper provided by Apple, I could make it works, but then I did something on my code and looks like now it's in an unstable state. Actually I have the original KeychainItemWrapper class, I just changed the following lines for checking the results:
OSStatus cpy = SecItemCopyMatching((CFDictionaryRef)genericPasswordQuery, (CFTypeRef *)&attributes);
NSLog(@"cpy result=%d", cpy);
if (cpy == noErr)
{
....
}
else
{
// No previous item found; add the new one.
result = SecItemAdd((CFDictionaryRef)[self dictionaryToSecItemFormat:keychainItemData], NULL);
if(result == errSecDuplicateItem) {
result = SecItemDelete((CFDictionaryRef)[self dictionaryToSecItemFormat:keychainItemData]);
NSLog(@"result=%d", result);
}
NSAssert( result == noErr, @"Couldn't add the Keychain Item." );
}
The first cpy variable returns -25300 (The item cannot be found)
SecItemAdd returns errSecDuplicateItem (–25299 the item already exists)
And then Im trying to remove the item if the function is saying that an item exists, and SecItemDelete returns -25300 again, so... now I cannot understand what's happening.
Im running this test with an iPad with iOS 6.1.3, any thoughs on this? Is there any way to reset the keychain completely and start from the scratch?
Thanks for any help