I am using WKWebView to open a url but before that it authenticates the user. It is working fine when we input the correct credentials but in case of wrong credentials, I am unable to find any delegate or function that can detect the failure.
Code:
func webView(_ webView: WKWebView, didReceive challenge:
URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
let user = "user"
let password = "password"
let credential = URLCredential(user: user, password: password, persistence: URLCredential.Persistence.forSession)
completionHandler(URLSession.AuthChallengeDisposition.useCredential, credential)
}
I can detect the previousFailureCount from URLAuthenticationChallenge, in case of failed response failureResponse always gives status code: 401. Any better way to detect the failure or success for URLAuthenticationChallenge?