diff options
author | Henrik Storch <henrik.storch@nextcloud.com> | 2022-04-14 09:35:08 +0300 |
---|---|---|
committer | Henrik Storch <henrik.storch@nextcloud.com> | 2022-04-20 14:15:50 +0300 |
commit | a6338cf7c879337bf36dc4d850ab0635ce3fc479 (patch) | |
tree | 95715cbbae87823d166198b662755943181b45a6 | |
parent | a1889dc51eb15184701623530ad0ffd0a3c9e9d3 (diff) |
Fix passcode not shownfix/save-photo-auth
- add small dismiss animation
Instead of modally displaying the passcode on top of the current VC use the privacy window to display the passcode on top of it.
This allows us to keep whatever VCs are below that intact and active (including system modals like QuickLook markup, Photo select, UIActivityVC, etc.), because the window can be displayed on top of everything (even alerts).
It also improves privacy, because tho the blur effect on top of whatever file is opened looks kinda cool, the purpose of adding a passcode is so that others can't see my files. The blur view gave away more information about what files are there / how many.
Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
-rw-r--r-- | iOSClient/AppDelegate.swift | 81 |
1 files changed, 40 insertions, 41 deletions
diff --git a/iOSClient/AppDelegate.swift b/iOSClient/AppDelegate.swift index 47e70827b..41f2b4bb3 100644 --- a/iOSClient/AppDelegate.swift +++ b/iOSClient/AppDelegate.swift @@ -188,14 +188,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD // L' applicazione entrerĂ in primo piano (attivo sempre) func applicationDidBecomeActive(_ application: UIApplication) { - + if !NCAskAuthorization.shared.isRequesting { // Privacy hidePrivacyProtectionWindow() } - - NCSettingsBundleHelper.setVersionAndBuildNumber() - + NCSettingsBundleHelper.setVersionAndBuildNumber() if account == "" { return } @@ -247,9 +245,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD if account == "" { return } - // Privacy - showPrivacyProtectionWindow() - + if CCUtility.getPrivacyScreenEnabled() { + // Privacy + showPrivacyProtectionWindow() + } + // Clear operation queue NCOperationQueue.shared.cancelAllQueue() // Clear download @@ -268,20 +268,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD func applicationDidEnterBackground(_ application: UIApplication) { if account == "" { return } - + // STOP TIMER UPLOAD PROCESS if NCUtility.shared.isSimulator() { networkingProcessUpload?.stopTimer() } - + if #available(iOS 13.0, *) { scheduleAppRefresh() scheduleBackgroundProcessing() } - + // Passcode presentPasscode { } - + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterApplicationDidEnterBackground) } @@ -299,7 +299,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD if account == "" { return } NCCommunicationCommon.shared.writeLog("initialize Main") - + // Registeration push notification NCPushNotification.shared().pushNotification() @@ -657,17 +657,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD // MARK: - Account Request func accountRequestChangeAccount(account: String) { - changeAccount(account) } func requestAccount() { - + if isPasscodePresented() { return } if !CCUtility.getAccountRequest() { return } - + let accounts = NCManageDatabase.shared.getAllAccount() - + if accounts.count > 1 { if let vcAccountRequest = UIStoryboard(name: "NCAccountRequest", bundle: nil).instantiateInitialViewController() as? NCAccountRequest { @@ -694,30 +693,21 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD } // MARK: - Passcode - + func presentPasscode(completion: @escaping () -> ()) { let laContext = LAContext() var error: NSError? - defer { - self.requestAccount() - } - - guard !account.isEmpty, CCUtility.isPasscodeAtStartEnabled() else { return } - - // If activated hide the privacy protection - hidePrivacyProtectionWindow() + defer { self.requestAccount() } - // Dismiss present window?.rootViewController? [ONLY PASSCODE] let presentedViewController = window?.rootViewController?.presentedViewController - if presentedViewController is NCLoginNavigationController { - return - } else { - presentedViewController?.dismiss(animated: false) - } + guard !account.isEmpty, CCUtility.isPasscodeAtStartEnabled(), !(presentedViewController is NCLoginNavigationController) else { return } + + // Make sure we have a privacy window (in case it's not enabled) + showPrivacyProtectionWindow() - let passcodeViewController = TOPasscodeViewController.init(passcodeType: .sixDigits, allowCancel: false) + let passcodeViewController = TOPasscodeViewController(passcodeType: .sixDigits, allowCancel: false) passcodeViewController.delegate = self passcodeViewController.keypadButtonShowLettering = false if CCUtility.getEnableTouchFaceID() && laContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) { @@ -731,8 +721,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD passcodeViewController.automaticallyPromptForBiometricValidation = false } } - - window?.rootViewController?.present(passcodeViewController, animated: true, completion: { + + // show passcode on top of privacy window + privacyProtectionWindow?.rootViewController?.present(passcodeViewController, animated: true, completion: { completion() }) } @@ -763,6 +754,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD func didInputCorrectPasscode(in passcodeViewController: TOPasscodeViewController) { DispatchQueue.main.async { passcodeViewController.dismiss(animated: true) { + self.hidePrivacyProtectionWindow() self.requestAccount() } } @@ -775,23 +767,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD // MARK: - Privacy Protection private func showPrivacyProtectionWindow() { - - guard CCUtility.getPrivacyScreenEnabled() else { return } - + guard privacyProtectionWindow == nil else { + privacyProtectionWindow?.isHidden = false + return + } + privacyProtectionWindow = UIWindow(frame: UIScreen.main.bounds) - + let storyboard = UIStoryboard(name: "LaunchScreen", bundle: nil) let initialViewController = storyboard.instantiateInitialViewController() self.privacyProtectionWindow?.rootViewController = initialViewController - + privacyProtectionWindow?.windowLevel = .alert + 1 privacyProtectionWindow?.makeKeyAndVisible() } func hidePrivacyProtectionWindow() { - privacyProtectionWindow?.isHidden = true - privacyProtectionWindow = nil + guard !(privacyProtectionWindow?.rootViewController?.presentedViewController is TOPasscodeViewController) else { return } + UIWindow.animate(withDuration: 0.25) { + self.privacyProtectionWindow?.alpha = 0 + } completion: { _ in + self.privacyProtectionWindow?.isHidden = true + self.privacyProtectionWindow = nil + } } // MARK: - Open URL |