When using the old UIWebView you could catch the requests by implementing a custom NSURLProtocol. I us this to handle requests that requires authentication.
I tried
WKWebView has a navigationDelegate property. If that delegate is set WKWebView will call the didReceiveAuthenticationChallenge method on that delegate if the method is implemented. You need to place your authentication code in this method. Example:
- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler {
NSURLCredential *credential = [[NSURLCredential alloc] initWithUser:@"bob"
password:@"pass"
persistence:NSURLCredentialPersistenceNone];
completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
}