Hi!
I have an WKWebView that opens an web page that requires basic authentication. This is how it is handled:
func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
if challenge.protectionSpace.host == "correcturl.com" {
let user = "user"
let password = "password"
let credential = URLCredential(user: user, password: password, persistence: URLCredential.Persistence.forSession)
challenge.sender?.use(credential, for: challenge)
completionHandler(.useCredential, credential)
}
completionHandler(.performDefaultHandling, nil)
}However on iOS 10.3 beta 1 and 2, ths code crashes at line 06 with the following error:
2017-02-13 14:33:31.094358+0200 MyApp[262:8266] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'The challenge was not sent by the receiver.'
*** First throw call stack:
(0x18c966fb8 0x18b3cc538 0x18c966f00 0x196587f2c 0x196587f94 0x1002db838 0x1002dba80 0x19637e5e4 0x1964c40e0 0x1963c7abc 0x1963c9c9c 0x196340ec8 0x1963436b4 0x19128c70c 0x19128c9e4 0x18c915404 0x18c914d74 0x18c912980 0x18c842d74 0x18e2ab074 0x192b9f988 0x10028b600 0x18b85159c)
libc++abi.dylib: terminating with uncaught exception of type NSExceptionI searched around a bit, and found some code in a WebKit repository that gave me some hint about the source of an error:
static void checkChallenge(NSURLAuthenticationChallenge *challenge)
{
if ([challenge class] != [WKNSURLAuthenticationChallenge class])
[NSException raise:NSInvalidArgumentException format:@"The challenge was not sent by the receiver."];
}Based on this, I did some type checking on the variables, and appears that the type of the "challenge" variable is different in iOS 10.2 and 10.3
in iOS 10.3 beta 1 and 2 it is WKNSURLAuthenticationChallenge
in iOS 10.2 it is NSURLAuthenticationChallenge
Initially this seems to be a bug somewhere in iOS (or WebKit shipped with it), but not sure. Thoughts?