diff --git a/ios/zeus/AppDelegate.m b/ios/zeus/AppDelegate.m index 0066566dee..0227ee467a 100644 --- a/ios/zeus/AppDelegate.m +++ b/ios/zeus/AppDelegate.m @@ -24,6 +24,31 @@ static void InitializeFlipper(UIApplication *application) { } #endif +/** + Deletes all Keychain items accessible by this app if this is the first time the user launches the app + */ +static void ClearKeychainIfNecessary() { + // Checks whether or not this is the first time the app is run + if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HAS_RUN_BEFORE"] == NO) { + // Set the appropriate value so we don't clear next time the app is launched + [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HAS_RUN_BEFORE"]; + + NSArray *secItemClasses = @[ + (__bridge id)kSecClassGenericPassword, + (__bridge id)kSecClassInternetPassword, + (__bridge id)kSecClassCertificate, + (__bridge id)kSecClassKey, + (__bridge id)kSecClassIdentity + ]; + + // Maps through all Keychain classes and deletes all items that match + for (id secItemClass in secItemClasses) { + NSDictionary *spec = @{(__bridge id)kSecClass: secItemClass}; + SecItemDelete((__bridge CFDictionaryRef)spec); + } + } +} + @implementation AppDelegate - (BOOL)application:(UIApplication *)application @@ -39,6 +64,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( InitializeFlipper(application); #endif + // Add this line to call the above function + ClearKeychainIfNecessary(); + RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"zeus"