I have a simple iOS native app that loads a single UIWebView. I would like the webView to show an error message if the app doesn\'t COMPLETELY finish loading the initial page in
My way is similar to accepted answer but just stopLoading when time out and control in didFailLoadWithError.
- (void)timeout{
if ([self.webView isLoading]) {
[self.webView stopLoading];//fire in didFailLoadWithError
}
}
- (void)webViewDidStartLoad:(UIWebView *)webView{
self.timer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(timeout) userInfo:nil repeats:NO];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
[self.timer invalidate];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(nullable NSError *)error{
//Error 999 fire when stopLoading
[self.timer invalidate];//invalidate for other errors, not time out.
}