Browse Source

Fix splash screen cancels request photo auth

- When `requestAuthorization` is called, app resigns active and displays alert
  - if user selects limited access, photo select view is shown
  - bc app is *in bg* app displays splash window. behind the alert When user selects option, iOS displays select photos view. But then app will become active and dismiss both splash and select phot view
-> Solution: Keep track if app is requesting access and don't automatically dismiss splash if becomes active. Manually hide splash screen after authorisation completes

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 3 years ago
parent
commit
23c3d471b8
2 changed files with 13 additions and 5 deletions
  1. 6 5
      iOSClient/AppDelegate.swift
  2. 7 0
      iOSClient/Utility/NCAskAuthorization.swift

+ 6 - 5
iOSClient/AppDelegate.swift

@@ -189,8 +189,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     // L' applicazione entrerà in primo piano (attivo sempre)
     // L' applicazione entrerà in primo piano (attivo sempre)
     func applicationDidBecomeActive(_ application: UIApplication) {
     func applicationDidBecomeActive(_ application: UIApplication) {
         
         
-        // Privacy
-        hidePrivacyProtectionWindow()
+        if !NCAskAuthorization.shared.isRequesting {
+            // Privacy
+            hidePrivacyProtectionWindow()
+        }
         
         
         NCSettingsBundleHelper.setVersionAndBuildNumber()
         NCSettingsBundleHelper.setVersionAndBuildNumber()
         
         
@@ -693,7 +695,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
 
     // MARK: - Passcode
     // MARK: - Passcode
     
     
-    func presentPasscode(completion: @escaping ()->()) {
+    func presentPasscode(completion: @escaping () -> ()) {
 
 
         let laContext = LAContext()
         let laContext = LAContext()
         var error: NSError?
         var error: NSError?
@@ -787,8 +789,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         privacyProtectionWindow?.makeKeyAndVisible()
         privacyProtectionWindow?.makeKeyAndVisible()
     }
     }
 
 
-    private func hidePrivacyProtectionWindow() {
-        
+    func hidePrivacyProtectionWindow() {
         privacyProtectionWindow?.isHidden = true
         privacyProtectionWindow?.isHidden = true
         privacyProtectionWindow = nil
         privacyProtectionWindow = nil
     }
     }

+ 7 - 0
iOSClient/Utility/NCAskAuthorization.swift

@@ -29,6 +29,8 @@ class NCAskAuthorization: NSObject {
         return instance
         return instance
     }()
     }()
 
 
+    private(set) var isRequesting = false
+
     func askAuthorizationAudioRecord(viewController: UIViewController?, completion: @escaping (_ hasPermission: Bool) -> Void) {
     func askAuthorizationAudioRecord(viewController: UIViewController?, completion: @escaping (_ hasPermission: Bool) -> Void) {
 
 
         switch AVAudioSession.sharedInstance().recordPermission {
         switch AVAudioSession.sharedInstance().recordPermission {
@@ -85,7 +87,12 @@ class NCAskAuthorization: NSObject {
             }
             }
             break
             break
         case PHAuthorizationStatus.notDetermined:
         case PHAuthorizationStatus.notDetermined:
+            isRequesting = true
             PHPhotoLibrary.requestAuthorization { allowed in
             PHPhotoLibrary.requestAuthorization { allowed in
+                self.isRequesting = false
+                DispatchQueue.main.async {
+                    (UIApplication.shared.delegate as? AppDelegate)?.hidePrivacyProtectionWindow()
+                }
                 DispatchQueue.main.async {
                 DispatchQueue.main.async {
                     if allowed == PHAuthorizationStatus.authorized {
                     if allowed == PHAuthorizationStatus.authorized {
                         completion(true)
                         completion(true)