当加载在WKWebView中的页面组件失败时,我试图记录一个错误,但是没有调用didFailProvisionalNavigation。
我从我的页面中删除了一个css文件来进行测试,但是没有结果。
当我在Google上加载页面时,我可以找到丢失的文件

WKWebView初始化为:
@interface MyWebView : UIViewController <WKNavigationDelegate>
@property(strong,nonatomic) WKWebView *loginWebView;
@end.m文件
@implementation MyWebView
- (void) initWebView {
// Set and Load the WebView
self.webView = [[WKWebView alloc] initWithFrame:self.view.frame];
self.webView.navigationDelegate = self;
[self.webView loadRequest:request];
[self.view addSubview:self.webView];
}然后,我实现了以下方法:
webView:decidePolicyForNavigationAction:decisionHandler:
webView:didStartProvisionalNavigation:
webView:didFinishNavigation:
webView:didFailNavigation:withError:
webView:didFailProvisionalNavigation:withError:前三个方法被调用,但是didFailNavigation和didFailProvisionalNavigation都没有被调用
通过查看文档 for didFailProvisionalNavigation,我们有
在web视图加载内容时发生错误时调用。
好的,一个内容失败了(css文件)并且方法没有被调用,我怎么做呢?
PS :我也尝试过使用UIWebView!
发布于 2020-10-14 10:24:43
- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler{
NSInteger statusCode = ((NSHTTPURLResponse *)navigationResponse.response).statusCode;
NSLog(@"statusCode:%ld", statusCode);
if (statusCode/100 == 4 || statusCode/100 == 5) {
NSLog(@"webview error:%@", navigationResponse.response);
}
decisionHandler(WKNavigationResponsePolicyAllow);
}这行得通!
https://stackoverflow.com/questions/41163722
复制相似问题