我目前正在Objective-C中使用WKWebKitView实现挑战 - 响应身份验证。 我实现了以下didReceiveAuthenticationChallenge:
-(void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler {
[[challenge sender] useCredential:[NSURLCredential credentialWithUser:@"app@email.com" password: @"******" persistence:NSURLCredentialPersistenceNone] forAuthenticationChallenge:challenge];}
我已经像这样实现了WebView:
NSURLRequest *request = [NSURLRequest requestWithURL:requestURL];
_wkView = [[WKWebView alloc] initWithFrame:self.view.frame];
_wkView.frame = CGRectMake(self.view.frame.origin.x,self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
[_wkView loadRequest:request];
[self.view addSubview:_wkView];
_wkView.navigationDelegate = self;
但是当调用URL时,应用程序崩溃并出现以下错误:
由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'传递完成处理程序 - [ReportViewerViewController webView:didReceiveAuthenticationChallenge:completionHandler:]未被调用'