UIWebView: webViewDidStartLoad/webViewDidFinishLoad delegate methods not called when loading certain URLs

前端 未结 3 1332
日久生厌
日久生厌 2021-02-04 05:06

I have basic web browser implemented using a UIWebView. I\'ve noticed that for some pages, none of the UIWebViewDelegate methods are called.

An

相关标签:
3条回答
  • 2021-02-04 05:19

    This isn't an iOS bug - the page isn't actually reloading. The UIWebView delegates are triggered following new page requests, but that page doesn't do that.

    Look very carefully at what happens in desktop Safari when you click the video link on that page as you describe. Make sure you pay attention to the address bar. The address will change, but critically the page will not reload.

    This is all handled by JavaScript, not by reloading the page. Simply put, the page never reloads, so there's no reason for the UIWebView delegates to be called.

    If you don't believe me, to conclusively prove this try repeating the steps you describe with JavaScript disabled. You'll notice the page behaves completely differently.

    0 讨论(0)
  • 2021-02-04 05:20

    Looks like this got fixed in iOS 4.2. It works in iOS 4.2.

    0 讨论(0)
  • 2021-02-04 05:44

    this is not good solution but im using NSTimer for updating status of buttons:

    - (BOOL)webView:(UIWebView *)_webview shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
        if (!_timer && [request.URL.absoluteString rangeOfString:@"youtube.com"].length != 0) {
            _timer = [NSTimer scheduledTimerWithTimeInterval:0.5
                                                      target:self
                                                    selector:@selector(checkNavigationStatus)
                                                    userInfo:nil
                                                     repeats:YES];
        }
    
        return YES;
    }
    
    //....
    //....
    //....
    
    - (void)checkNavigationStatus
    {
        // Check if we can go forward or back
        backButton.enabled = self.webView.canGoBack;
        forwardButton.enabled = self.webView.canGoForward;
    }
    
    0 讨论(0)
提交回复
热议问题