WKWebView does not load https URL? WKWebView does not load https URL? ios ios

WKWebView does not load https URL?

Add this to your plist

<key>NSAppTransportSecurity</key><dict>    <key>NSAllowsArbitraryLoads</key>    <true/></dict>

Here's the explanation for this change in 9.0http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/

Also if you want to set it up more secure it gives you a more complex way to do that.

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

If you are in a sandboxed macOS app, you'll need to set the Outgoing Connections (Client) capability, you won't need to mess with Allow Abitrary Loads which shouldn't come into play for trusted https requests. Xcode Capabilities Screenshot showing the Outgoing Connections (Client) checkbox checked

For iOS however, allowing client connections is the default, so you may need to implement WKNavigationDelegate methods to handle security. Make sure you aren't just trusting untrusted certificates though. This Swift Talk video from objc.io is the best resource I know of, definitely worth 20 minutes if you're working in this area: https://talk.objc.io/episodes/S01E57-certificate-pinning