Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WKWebView shows blank page when trying to load a https webpage under a local network

I am trying to load a webpage that is under a local network after the device connects to a specific WiFi.

I am getting this error:

WebPageProxy::didFailProvisionalLoadForFrame: frameID = 3, domain = NSURLErrorDomain, code = -1202

I can load any other webpage I try with no issues.

I can pull up the webpage on Safari in the xcode simulator and I am able to see it, but I do get the "This Connection is Not Private" page before and have to click the "visit this website" button. Not sure if this is the problem.

like image 465
davidatherton Avatar asked Oct 26 '25 05:10

davidatherton


1 Answers

In addition to allow arbitrary load in Info you may need to implement this function in your WKNavigationDelegate

func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
    guard let serverTrust = challenge.protectionSpace.serverTrust  else {
        completionHandler(.useCredential, nil)
        return
    }
    let credential = URLCredential(trust: serverTrust)
    completionHandler(.useCredential, credential)
    
}
like image 119
Gualtiero Frigerio Avatar answered Oct 29 '25 08:10

Gualtiero Frigerio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!