Browse Source

Fix crash on URLAuthenticationChallenge #982

Marino Faggiana 7 years ago
parent
commit
8c764da793
1 changed files with 7 additions and 1 deletions
  1. 7 1
      iOSClient/Library/SwiftWebVC/SwiftWebVC.swift

+ 7 - 1
iOSClient/Library/SwiftWebVC/SwiftWebVC.swift

@@ -358,7 +358,13 @@ extension SwiftWebVC: WKNavigationDelegate {
     
     
     public func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
     public func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
         
         
-        completionHandler(Foundation.URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust!))
+        if challenge.previousFailureCount > 0 {
+            completionHandler(Foundation.URLSession.AuthChallengeDisposition.cancelAuthenticationChallenge, nil)
+        } else if let serverTrust = challenge.protectionSpace.serverTrust {
+            completionHandler(Foundation.URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: serverTrust))
+        } else {
+            print("unknown state. error: \(String(describing: challenge.error))")
+        }
     }
     }
 
 
 }
 }