Search code examples
iossskeychain

SSKeychain delete account


I want to delete an account from my SSKeychain. I only get the method to delete the password, but the account is still in the keychain.

Is there a way to delete an account or clear the SSKeychain?


Solution

  • What I'd use to delete an account,:
    1. Instance a SSKeychainQuery object.
    2. set the service and the account, that I want to delete.
    3. call the method deleteItem:

    //1  
    SSKeychainQuery *query = [[SSKeychainQuery alloc] init];  
    //2  
    query.service = @"MyService";  
    query.account = @"account2";  
    //3  
    [query deleteItem:nil];
    

    Then if you call

    NSLog(@"%@",[SSKeychain accountsForService:@"MyService"]);
    

    This will print all the accounts for the service called "MyService" or null if there's not "MyService"