How to detect when a UIWebView has completely finished loading?

ORStudios picture ORStudios · Aug 22, 2014 · Viewed 26.5k times · Source

I am trying to build a filter for a UIWebView and I am struggiling to detect when the UIWebView has completely finished loading. I have used the following two methods

– webView:shouldStartLoadWithRequest:navigationType:
– webViewDidFinishLoad:

but the issue is that these will be called multiple times when a page has frames and additional content to load.

What I need is to know when the view has completely loaded and there is no more content to fetch. Then when the content has loaded I can check to URL of the page against a list of approved URLS.

ANy ideas?

Answer

Paresh Navadiya picture Paresh Navadiya · Nov 4, 2014

Use the UIWebViewDelegate protocol method webViewDidFinishLoad and webView's isLoading property

 - (void)webViewDidFinishLoad:(UIWebView *)webView
 {
    //Check here if still webview is loding the content
    if (webView.isLoading)
       return;

    //after code when webview finishes
    NSLog(@"Webview loding finished");
 }