How do you reset an iPhone App's Keychain?

前端 未结 4 1664
清酒与你
清酒与你 2020-12-13 06:44

I would like to know if there is a way to reset my app\'s Keychain. I am wondering whether anything like [NSUserDefaults resetStandardUserDefaults] exists for k

4条回答
  •  庸人自扰
    2020-12-13 07:36

    - (void)resetKeychainItem
    {
        OSStatus junk = noErr;
        if (!keychainItemData) {
            self.keychainItemData = [[NSMutableDictionary alloc] init];
        } else if (keychainItemData){
            NSMutableDictionary *tempDictionary = [self dictionaryToSecItemFormat:keychainItemData];
            junk = SecItemDelete((CFDictionaryRef)tempDictionary);
            if ( junk != noErr ) {
                UIAlertView *dialog = [[UIAlertView alloc] initWithTitle:@"Keychain Error" message:[NSString stringWithFormat:@"A problem with updating the secure Keychain items with this information (likely, this email address information is duplicated in another Player).  Error code: %d %@", junk, [self resultText:-junk]] delegate:self cancelButtonTitle:NSLocalizedStringFromTable(@"Ok", @"Localizable", @"display text") otherButtonTitles:nil];
                [dialog show];
                [dialog release];
                //NSAssert( junk == noErr || junk == errSecItemNotFound, @"Problem deleting current dictionary." );
                return;
            }
        }
    
        // Default attributes for keychain item.
        [keychainItemData setObject:@"" forKey:(id)kSecAttrAccount];
        [keychainItemData setObject:@"" forKey:(id)kSecValueData];
        [keychainItemData setObject:@"" forKey:(id)kSecAttrLabel];
        [keychainItemData setObject:@"" forKey:(id)kSecAttrDescription];
        [keychainItemData setObject:@"" forKey:(id)kSecAttrComment];
        // Default data for keychain item.
        [keychainItemData setObject:@"" forKey:(id)kSecAttrModificationDate];
        [keychainItemData setObject:@"" forKey:(id)kSecAttrService];
    
    
    }
    

提交回复
热议问题