Allow unverified ssl certificates in WKWebView

后端 未结 6 981
既然无缘
既然无缘 2020-12-12 21:08

I\'m trying to load a HTTPS url with an self-signed certificate in a WKWebView for iOS 8 and it keeps failing. The workaround used with UIWebView (using setAllowsAnyHTTPSCer

6条回答
  •  有刺的猬
    2020-12-12 21:36

    Try this:

     func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
    
        if let serverTrust = challenge.protectionSpace.serverTrust {
            let credential = URLCredential(trust: serverTrust)
            completionHandler(.useCredential, credential)
        }else{
             completionHandler(.useCredential, nil)
        }
    
    }
    

提交回复
热议问题