3

I'm trying to throw up an alert to users when a UIWebView fails to load a page because it can't reach the server. I'm using the delegate method:

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
  // show NSAlert telling user there was a problem
}

(docs: https://developer.apple.com/library/ios/documentation/uikit/reference/UIWebViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIWebViewDelegate/webView:didFailLoadWithError:)

The problem is that this method is called for other things as well - such as when you visit another page before the previous one has finished loading, etc. What specific NSError's should I check for for throwing my NSAlert? What NSError's does UIWebView throw? I can't see this documented anywhere!

Thanks.

Sam Heather
  • 1,493
  • 3
  • 19
  • 42
  • Try to simulate a failed loading and figure out what error CODE is being thrown. Then, once you have the error CODE just check if the NSError object code is equal to what you've figured out. – Noam Solovechick Jun 29 '14 at 01:36
  • @Noam Solovechick thanks that's a good idea actually - I was thinking too much like Java exceptions. I'll give it a go. – Sam Heather Jun 29 '14 at 11:16
  • @NoamSolovechick once I've got the error codes, is there anywhere I can find a real description of this error? – Sam Heather Jun 29 '14 at 16:51

1 Answers1

0

If anyone does come up across the same problem, the solution ended up been to: NSLog the error code and description every time the error function was called. Do some stuff in my app that would generate errors Watch the output to establish which codes corresponded to which actions (the error descriptions helped).

This is achieved simply by:

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    NSLog(@"%d", error.code);
    NSLog(error.localizedDescription);
}
Sam Heather
  • 1,493
  • 3
  • 19
  • 42