how to delete KeyChainItemData and genericPasswordQuery items from iOS keychain
I have been having some troubles with my keychain, I think mainly because I was not aware of how it worked when I first started using it, I tried several variations of adding data and strings passwords etc into my keychain thinking that when I deleted the app from my device it would clear the keychain... I now know this is not how the keychain works so was hoping I could get some help clearing up the junk that is in my keychain now.
The thing is I am now trying to pass some information to my keychain but am receiving the following error
*** Assertion failure in -[KeychainItemWrapper writeToKeychain], /Users/imac/Documents/Iphone applications/Keystone/Keystone/KeychainItemWrapper.m:268
2013-07-23 11:07:46.086 Keystone[2769:907] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn't add the Keychain Item.'
This error happens when I try to pass some info into the keychainwrapper I have declares as illustrated in the code below.
[keychainItem setObject:@"somestringhere" forKey: (__bridge id)kSecAttrService];
I think the code is actually fine, because I think the current junk in my keychain is preventing me from correctly adding to the new items to the keychain. I implement the wrapper like this
KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"gena" accessGroup:@"KeyStone.com.WHATWHAT.GenericKeychainSuite"];
I can see this in my debug area.
As you can see KeyChainItemData and genericPasswordQuery are already in my keychain with 6 - 5 objects?! weird. From that I have tried to clear my keychain using the following code...
[keychainItem resetKeychainItem];
The only issue being is that this dose nothing to help me. So I was wondering what I might need to do in order to delete these KeyChainItemData and genericPasswordQuery entries that seem to be in my keychain preventing me from adding the correct entries.
Any help would be greatly appreciated.
UPDATE: So from doing further research when I declare KeychainItemWrapper thats when all of those values are showing themselves in my debugging area, however after trying the same code on a different device that has not had any keychain development done on it it still showed those same values. So I figure its not on the device its got to be something else... hopefully that makes sense.. I will continue trying to find a solution.
Take a look at this short step by step example on useyourloaf.com
It covers simple iPhone keychain access. It has examples to search, create, update and delete an item from the keychain.
You might also want to look at the Apple Developer Keychain Services Reference. The coommand you are looking for is SecItemDelete.
I'd recommend against using KeychainItemWrapper. After working with the KeychainItemWrapper for multiple projects I kept finding multiple bugs and edge cases that weren't considered so I created my own simpler wrapper for accessing the Keychain https://github.com/reidmain/FDKeychain
It works very similar to NSDictionary with just setValue: and objectForKey: methods.
链接地址: http://www.djcxy.com/p/83278.html