Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have an UIWebView in my iOS app, which displays a very long web page. If the page fails to load for some reason, I display an alert in my webView:didFailLoadWithError: method. However, it is possible that user would tap some link BEFORE the page is fully loaded, and UIWebView treats that as an error as well, which I want to ignore silently. Is there any way to find out that a page loading error originates from user tapping a link?

share|improve this question
Just a quick thought that comes to mind....what if you just disable the webview and enable it at webViewDidFinishLoad:? – user1135469 20 hours ago
Yeah, that is my "last resort" option — to make the UI unresponsive for a while. That would be less damaging then confusing the user with the wrong error message, but still bad. – MigMit 19 hours ago
Well if you do go with that, you could probably place some sort of loading indicator in the middle of the screen so the user knows somethings happening. – user1135469 19 hours ago
1  
If you want to ignore it, you can have a look at the error codes of the webView:didFailLoadWithError: errors. I suspect that the error code for the "tap link before page is fully loaded" would be different to the others so just use if([error code] == {figure out what the code is for that case by NSLog(@"error: %@")}) return; – user1135469 18 hours ago
Oh, yes, stupid me. It's NSURLErrorCancelled, which seems to be safe to ignore. Thanks. – MigMit 18 hours ago

1 Answer

As user1135469 suggested, error.code seems to be the key. It's NSURLErrorCancelled when the user taps the link, and it's safe to just ignore this error code.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.