WKWebView does not load https URL?

前端 未结 6 582
予麋鹿
予麋鹿 2021-02-07 00:16

I have a WKWebView which should load the following url:

https://buchung.salonmeister.de/place/#offer-details-page?id=907599&venueId=301655

6条回答
  •  日久生厌
    2021-02-07 01:05

    For me, the issue was caused by server trust check from the WKWebView.

    To fix this I had to handle the challenge authentication callback and return a server trust credential.

    Swift 4

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

提交回复
热议问题