Search code examples
iosswiftios12

HTTP load request is not working in iOS12


I having an application which open the direction between two location in a webview using "http://maps.google.com" URL. but it is not working in iOS12. And also enabled the exceptional domain in App transport security plist value. Even though it is not working.


Solution

  • 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)
        }
    }