17
votes

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

An example page in which this happens is: http://www.youtube.com/user/google. Here are the steps to reproduce the issue (make sure you insert NSLog calls in your controller's UIWebViewDelegate methods):

  1. Load the above youtube URL into the UIWebView [notice that here, the UIWebViewDelegate methods do get called when the page loads]
  2. Touch the "Uploads" category on the page
  3. Touch any video in that category [issue: notice that a new page is loaded, but none of the UIWebView delegates are called]

I know that this is not an issue of UIWebView's delegate not being set properly, since the delegate methods do get invoked when loading other links (e.g. if you try clicking on a link that takes you outside of youtube, you'll notice the delegate methods getting called).

My gut feeling initially was that it might be because the page is loaded using AJAX, which may not invoke the delegate method. But then when I checked the iPhone's Safari, it did not exhibit this problem, so it must be something on my side.

I've also noticed that Three20's TTWebController has the exact same issue as I'm having.

But the problem that arises from this issue is that without the delegate methods called, I'm unable to update the UI to enable/disable the back and forward browsing buttons when new requests are loaded.

And idea why this is happening or how can I work around it to update the UI when a new request is made?

3
I'm starting to think this might be an iOS bug?Dia Kharrat
I'm not on my Mac ATM to try the issue, but it's interesting that you've mentioned it happens on some video page. Could it be that the page keeps the connection opened for the streaming? I would propose that you try making a NSURLRrquest with the page URL and see if the connection is getting closed after the HTML data is loaded.pmilosev
Hey, did you ever solved this problem? I'm playing with m.youtube.com and it's a nightmare.Lior Frenkel

3 Answers

20
votes

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.

1
votes

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;
}
-3
votes

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