Tuesday, 25 August 2020

How to display invalid SSL Certificate Alert and load URL only if user agrees in WKWebView

HI I'm working on a WKWebView based web browser, Now the problem is I want to display some Alert when the URL being load, has invalid ssl certificate and if user still wants to open the URL then only load that URL otherwise display some error page.

I know how to bypass the bad ssl certificate using the following WKWebView navigationDelegate method

 func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
    let trust = challenge.protectionSpace.serverTrust!
    let exceptions = SecTrustCopyExceptions(trust)
    SecTrustSetExceptions(trust, exceptions)
    completionHandler(.useCredential, URLCredential(trust: trust))
}

But this will load the URL without notifying the user, something I don't want.

Any help would be much appreciated. Thank in advance.



from How to display invalid SSL Certificate Alert and load URL only if user agrees in WKWebView

No comments:

Post a Comment