I'm making a web browser and like every other web browser I'd like to inform the user of the error that occurred when a web page failed to load.
Currently, I'm displaying the localizedDescription of the error in the didFailProvisionalNavigation method. That's all!
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error { [self presentError:error.localizedDescription animated:YES]; [_delegate webViewDidFailNavigation:self error:error]; }
The presentError method handles some custom UI stuff irrelevant to the question.
The method above works excellent for displaying the usual errors such as:
- The internet connection appears to be offline.
- A server with the specified hostname could not be found.
But it also displays some unusual errors such as:
- The operation could not be completed(NSURL ErrorDomain error -999)
I don't like this method for two reasons:
- The error message displays some technical stuff "NSURL" but I could ignore that.
- Most importantly most of the time when the error above is being displayed the web page is perfectly usable but since it's a didFailProvisionalNavigation error I have to disable the page from being used and instead present the error.
I'm not aware of what other minor errors could occur that shouldn't be handled the way I'm handling them. Unfortunately, I don't know of a way to distinguish between major errors such as "Connection appears to be offline" and minor errors such as "Operation couldn't be completed".
What is the standard way of handling navigation failures?
1 Answers
Answers 1
Instead of
webView(_:didFailProvisionalNavigation:withError:)
why do you not use this?
webView(_:didFail:withError:)
It seems that should only be called when there is an error preventing the site from displaying content, not when a page is already rendered and trying to load the next page.
0 comments:
Post a Comment