4

Our iOS app has a Web View that is rendering pages from file: URLs. When the user touches an <A> element to switch pages, about 20% of the time, it gets stuck as follows:

  1. User taps <A> link
  2. We get WebView.shouldStartLoadWithRequest callback
  3. We get WebView.webViewDidStartLoad callback
  4. nothing happens after this

The screen still shows the original page with the link on it. We can break the logjam in two ways:

  1. Rotate the device
  2. Tap the screen

At that point, the page will immediately finish loading.

We used the recipe from here:

Javascript console.log() in an iOS UIWebView

to allow us some insight into the page load. We put the javascript-side stuff right in the first script file we load on the page, and it doesn't print its message until after we do the rotate-or-tap workaround.

So it appears that it is getting stuck somewhere between starting to load the page, and starting to evaluate the stuff on the page.

We have tried a number of work-around, none of which helped:

  • Setting location.href instead of using the tag
  • Setting location.href from javascript timeout
  • In the didStartLoad callback, created a thread that called setNeedDisplay on the webView over and over

Any idea what we might be doing wrong?

Community
  • 1
  • 1
Joshua Smith
  • 3,689
  • 4
  • 32
  • 45
  • Can you comment out everything, or most everything, on the pages and still duplicate the problem? That would be my first approach to diagnosing. Maybe it's a page size/memory problem. Are you NSLog'ging if there's an app memory error? – Matt H Nov 04 '11 at 23:52
  • Same weird behavior in my App. Did you found a solution? – olfuerniss Nov 07 '11 at 07:15
  • No answer yet, although I'm somewhat glad that we're not alone. I've seen the problem with completely trivial pages, and as I said, we've tried adding logging right at the beginning of the page we're going to, and it isn't happening. So webkit has left the old page and started loading the new one, but just stopped before it parsed anything. – Joshua Smith Nov 08 '11 at 20:28

2 Answers2

2

You could use gdb within XCode to debug the problem. I think canidates for messages that could have break points are:

- (void)webViewDidStartLoad:(UIWebView *)webView
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error

I'd also add a break in whatever UIViewController is showing your UIWebView for:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

Then you could step through and hopefully catch what's wrong with your UIWebView subclass.

If you don't want to add breakpoints you could just run your app in the XCode debugger and hit the "pause execution" button above the console window when your app becomes unresponsive while loading.

GDB Pause Execution Button

It's hard to know what's going on without any code to go off of but I bet Xcode can help you find the issue quickly.

Good luck!

Joel
  • 2,928
  • 2
  • 24
  • 34
  • This was the clue we needed. What we figured out is that there was a kind of a soft deadlock between the UIWebView and our Open GL rendering code (we're layering a web view over an opengl image). The Web view was hung up waiting on a semaphore. We fixed the problem by simply turning off our GL refresh loop during page loads. – Joshua Smith Nov 17 '11 at 21:36
0

Found the solution for this weird behavior, at least in my case.

In my App i've created a subclass of UIWebView. I know that Apples documentation notes that you should not subclass UIWebView. But it's "necessary" in my App.

The problem was, that i've overwritten scrollViewDidEndDragging:willDecelerate: without calling super.

- (void) scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    // my code
}

becomes to

- (void) scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    [super scrollViewDidEndDragging:scrollView willDecelerate:decelerate];
    // my code
}

Now it always loads the web site when tapping on a html link.

olfuerniss
  • 317
  • 3
  • 5
  • We were subclassing UIWebView, but we weren't overriding that method. Anyway, we just refactored to eliminate the subclassing (didn't realize that was a "should not"). The problem remains. – Joshua Smith Nov 14 '11 at 18:26