WKWebViewJavascriptBridge webView:didReceiveAuthenticationChallenge crash,现象如下:
didReceiveAuthenticationChallenge这个crash一般是因为webview重定向时缺乏信任证书或相应的页面不允许外部访问。WKWebViewJavascriptBridge相关联的crash,是在WKWebViewJavascriptBridge内部的didReceiveAuthenticationChallenge方法。一般有以下两种解决方案:
第一种方法:
#pragma mark --- 缺乏证书信任 - (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *_Nullable))completionHandler { if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { if (challenge.previousFailureCount == 0) { NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]; completionHandler(NSURLSessionAuthChallengeUseCredential, credential); } else { completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, nil); } } }
这种情况就是强制信任,告诉webview可以直接跳转,就类似浏览器弹出是否信任该网站,选择信任的情况。
第二种方法:
这种一般是因为H5页面端的跳转页面出错的问题,跳转到指定环境允许下才能访问的页面。例如:接入微信支付,H5端点击支付时,访问了微信小程序支付的方式,没有调起微信应用跳转。由于这种情况微信只允许在微信内部环境访问,所以直接闪退。
当报错didReceiveAuthenticationChallenge时,开头又不是webview时,一般考虑第二种情况。
如有错误,欢迎指正。
网友评论