Browse Source

fix checkTrustedChallenge return in main thread

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 years ago
parent
commit
7cc94cf261
2 changed files with 22 additions and 22 deletions
  1. 19 21
      iOSClient/AppDelegate.swift
  2. 3 1
      iOSClient/Networking/NCNetworking.swift

+ 19 - 21
iOSClient/AppDelegate.swift

@@ -542,33 +542,31 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
               host == currentHost
         else { return }
 
-        DispatchQueue.main.async {
-            let certificateHostSavedPath = CCUtility.getDirectoryCerificates()! + "/" + host + ".der"
-            var title = NSLocalizedString("_ssl_certificate_changed_", comment: "")
+        let certificateHostSavedPath = CCUtility.getDirectoryCerificates()! + "/" + host + ".der"
+        var title = NSLocalizedString("_ssl_certificate_changed_", comment: "")
 
-            if !FileManager.default.fileExists(atPath: certificateHostSavedPath) {
-                title = NSLocalizedString("_connect_server_anyway_", comment: "")
-            }
+        if !FileManager.default.fileExists(atPath: certificateHostSavedPath) {
+            title = NSLocalizedString("_connect_server_anyway_", comment: "")
+        }
 
-            let alertController = UIAlertController(title: title, message: NSLocalizedString("_server_is_trusted_", comment: ""), preferredStyle: .alert)
+        let alertController = UIAlertController(title: title, message: NSLocalizedString("_server_is_trusted_", comment: ""), preferredStyle: .alert)
 
-            alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .default, handler: { action in
-                NCNetworking.shared.writeCertificate(host: host)
-            }))
+        alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .default, handler: { action in
+            NCNetworking.shared.writeCertificate(host: host)
+        }))
 
-            alertController.addAction(UIAlertAction(title: NSLocalizedString("_no_", comment: ""), style: .default, handler: { action in }))
+        alertController.addAction(UIAlertAction(title: NSLocalizedString("_no_", comment: ""), style: .default, handler: { action in }))
 
-            alertController.addAction(UIAlertAction(title: NSLocalizedString("_certificate_details_", comment: ""), style: .default, handler: { action in
-                if let navigationController = UIStoryboard(name: "NCViewCertificateDetails", bundle: nil).instantiateInitialViewController() as? UINavigationController {
-                    let viewController = navigationController.topViewController as! NCViewCertificateDetails
-                    viewController.delegate = self
-                    viewController.host = host
-                    self.window?.rootViewController?.present(navigationController, animated: true)
-                }
-            }))
+        alertController.addAction(UIAlertAction(title: NSLocalizedString("_certificate_details_", comment: ""), style: .default, handler: { action in
+            if let navigationController = UIStoryboard(name: "NCViewCertificateDetails", bundle: nil).instantiateInitialViewController() as? UINavigationController {
+                let viewController = navigationController.topViewController as! NCViewCertificateDetails
+                viewController.delegate = self
+                viewController.host = host
+                self.window?.rootViewController?.present(navigationController, animated: true)
+            }
+        }))
 
-            self.window?.rootViewController?.present(alertController, animated: true)
-        }
+        window?.rootViewController?.present(alertController, animated: true)
     }
 
     func viewCertificateDetailsDismiss(host: String) {

+ 3 - 1
iOSClient/Networking/NCNetworking.swift

@@ -169,7 +169,9 @@ import Photos
         #if !EXTENSION
         defer {
             if !isTrusted {
-                (UIApplication.shared.delegate as? AppDelegate)?.trustCertificateError(host: host)
+                DispatchQueue.main.async {
+                    (UIApplication.shared.delegate as? AppDelegate)?.trustCertificateError(host: host)
+                }
             }
         }
         #endif