diff --git a/apps/ios/Shared/AppDelegate.swift b/apps/ios/Shared/AppDelegate.swift index 24c0eeb605..7204625ad4 100644 --- a/apps/ios/Shared/AppDelegate.swift +++ b/apps/ios/Shared/AppDelegate.swift @@ -16,6 +16,7 @@ class AppDelegate: NSObject, UIApplicationDelegate { application.registerForRemoteNotifications() if #available(iOS 17.0, *) { trackKeyboard() } NotificationCenter.default.addObserver(self, selector: #selector(pasteboardChanged), name: UIPasteboard.changedNotification, object: nil) + removePasscodesIfReinstalled() return true } @@ -127,6 +128,19 @@ class AppDelegate: NSObject, UIApplicationDelegate { BGManager.shared.receiveMessages(complete) } + private func removePasscodesIfReinstalled() { + // Check for the database existence, because app and self destruct passcodes + // will be saved and restored by iOS when a user deletes and re-installs the app. + // In this case the database and settings will be deleted, but the passcodes won't be. + // Deleting passcodes ensures that the user will not get stuck on "Opening app..." screen. + if (kcAppPassword.get() != nil || kcSelfDestructPassword.get() != nil) && + !UserDefaults.standard.bool(forKey: DEFAULT_PERFORM_LA) && !hasDatabase() { + _ = kcAppPassword.remove() + _ = kcSelfDestructPassword.remove() + _ = kcDatabasePassword.remove() + } + } + static func keepScreenOn(_ on: Bool) { UIApplication.shared.isIdleTimerDisabled = on }