Search code examples
iosxcode6ios-simulator

How do I reset the keychain in simulator?


I've stored some data in the simulator keychain for sensitive data. Now I must test what happens if that data is not yet present.

But I am unable to reset my simulator's keychain to test that.

I've tried deleting the app from the simulator and then do a reset content and settings. But the keychain data is still present.

Edit: YES, I HAVE TRIED "RESET CONTENT AND SETTINGS", but that does not work


Solution

  • Easiest way would be to open your simulator and go to:

    "iOS Simulator -> Reset Content and Settings" This will reset everything in the simulator and will return it to Default settings.

    If you want to do it through code you can do it like this:

    NSArray *secItemClasses = @[(__bridge id)kSecClassGenericPassword,
                           (__bridge id)kSecClassInternetPassword,
                           (__bridge id)kSecClassCertificate,
                           (__bridge id)kSecClassKey,
                           (__bridge id)kSecClassIdentity];
    for (id secItemClass in secItemClasses) {
        NSDictionary *spec = @{(__bridge id)kSecClass: secItemClass};
        SecItemDelete((__bridge CFDictionaryRef)spec);
    }