Instance Method

webView(_:didReceive:completionHandler:)

Called when the web view needs to respond to an authentication challenge.

Declaration

optional func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void)

Parameters

webView

The web view receiving the authentication challenge.

challenge

The authentication challenge.

completionHandler

A block to invoke to respond to the challenge. The disposition parameter must be one of the constants of the enumerated type URLSession.AuthChallengeDisposition. When disposition is URLSession.AuthChallengeDisposition.useCredential, the credential parameter specifies the credential to use, or nil to continue without a credential.

Discussion

If you do not implement this method, the web view will respond to the authentication challenge with the URLSession.AuthChallengeDisposition.rejectProtectionSpace disposition.