I m trying to log an error when a page component loaded in a WKWebView
fail, but didFailProvisionalNavigation
is not called.
I removed a css file from my page to test with it, but no result.
When I load the page on Google Chrome I can find the missing file
The WKWebView is initialised as:
@interface MyWebView : UIViewController <WKNavigationDelegate>
@property(strong,nonatomic) WKWebView *loginWebView;
@end
The .m file
@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];
}
Then I implemented the methods bellow:
webView:decidePolicyForNavigationAction:decisionHandler:
webView:didStartProvisionalNavigation:
webView:didFinishNavigation:
webView:didFailNavigation:withError:
webView:didFailProvisionalNavigation:withError:
The first three methods get called, but neither didFailNavigation
nor didFailProvisionalNavigation
are called
By looking at the documentation for didFailProvisionalNavigation
we have
Called when an error occurs while the web view is loading content.
Well, a content has failed (css file) and the method is not called, how can I do this?
PS : I also tried using UIWebView
!
- (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);
}
this works!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With