Created
February 23, 2010 01:36
-
-
Save norio-nomura/311748 to your computer and use it in GitHub Desktop.
SecItemDelete sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)removeObjectForKey:(NSString*)key { | |
#if !TARGET_IPHONE_SIMULATOR | |
@synchronized(self) { | |
if (!deleteQueryDictionary) { | |
deleteQueryDictionary = [[NSMutableDictionary alloc]initWithObjectsAndKeys: | |
(id)kSecClassGenericPassword, (id)kSecClass, | |
key, (id)kSecAttrAccount, | |
(id)kSecMatchLimitAll, (id)kSecMatchLimit, | |
(id)kCFBooleanTrue, (id)kSecReturnAttributes, | |
nil]; | |
} else { | |
[deleteQueryDictionary setObject:key forKey:(id)kSecAttrAccount]; | |
} | |
NSArray *itemList = nil; | |
OSStatus osStatus = SecItemCopyMatching((CFDictionaryRef)deleteQueryDictionary, (CFTypeRef *)&itemList); | |
if (osStatus == noErr) { | |
for (NSDictionary *item in itemList) { | |
NSMutableDictionary *query = [item mutableCopy]; | |
[query setValue:(id)kSecClassGenericPassword forKey:(id)kSecClass]; | |
osStatus = SecItemDelete((CFDictionaryRef)query); | |
if (osStatus != noErr) { | |
NSLog(@"osStatus:%d",osStatus); | |
} | |
[query release]; | |
} | |
} else if (osStatus != errSecItemNotFound){ | |
NSLog(@"osStatus:%d",osStatus); | |
} | |
[itemList release]; | |
} | |
#else | |
[[NSUserDefaults standardUserDefaults] removeObjectForKey:key]; | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment