I had a project where we display a UIWebView, where on failure to load, an alert will be displayed informing the user of the error.
This is a bit troublesome, since there are lots of UIWebView errors, and we cannot handle all of them immediately. Silently ignoring the errors would have been better (this just retains what’s loaded on the UIWebView, mostly blank, unless some part of the page has already been loaded).
But, if you need to display an alert like me, here are some you should look out for. By looking out for, I mean that you should handle it such that when the following errors are received, the alert will not be displayed (because they are errors that the user should not be concerned or informed about!).
Before that, you handle the errors in the following delegate method:
1 |
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error |
1. If the URL redirects to another URL, we will receive an NSURLErrorCancelled error.
1 |
[error.domain isEqualToString:@"NSURLErrorDomain"] && error.code == NSURLErrorCancelled |
2. If the page contains links to the AppStore, tapping the link will return an error (but the AppStore link will still be handled by iOS).
1 |
[error.domain isEqualToString:@"WebKitErrorDomain"] && error.code == 102 |
3. If the URL is a direct link to a Video/Audio, we will receive an error (“Plug-in handled load”) even if the video/audio will play.
1 |
[error.domain isEqualToString:@"WebKitErrorDomain"] && error.code == 204 |
That’s all for now. Will update this post as soon as new errors that need’s to be handled