Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 671
Tycho Pandelaar Avatar asked Jul 03 '15 09:07

Tycho Pandelaar


People also ask

How do I wipe data from simulator?

Run and stop an emulator, and clear data To stop a running emulator, click Menu and select Stop. To clear the data for an emulator, select Wipe Data. Or click Menu and select Wipe Data.

How do you restart an app on iPhone simulator?

shift+command+H twice to simulate the double tap of home button. swipe your app's screenshot upward to close it.

How do I clear IOS keychain?

In the Keychain Access app on your Mac, if your keychains aren't visible, choose Window > Keychain Access. Select a keychain in the Keychains list. Choose File > Delete Keychain [keychain name].


3 Answers

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);
}
like image 108
Segev Avatar answered Oct 24 '22 11:10

Segev


There is a race condition with resetting contents & settings sometimes not working. If it doesn't work, try again. If it really keeps on not working, quit Simulator.app, wait a few seconds, then run xcrun simctl erase <Device UDID> from Terminal. You can get the device's UDID by running xcrun simctl list.

This race bug should be addressed in the latest Xcode 7 Beta.

like image 41
Jeremy Huddleston Sequoia Avatar answered Oct 24 '22 10:10

Jeremy Huddleston Sequoia


Xcode 13.1

You can erase the keychain data on the simulator from option Device -> Erase All Content and Settings like the below image.

Just remember, this option will clear all current data on your simulator.

enter image description here

Hope to help someone!

like image 44
Tuan Nguyen Avatar answered Oct 24 '22 11:10

Tuan Nguyen