UIWebView stuck after webViewDidStartLoad

Our iOS application has a web view that displays pages from a file: URL. When the user touches the <A> element to switch pages, about 20% of the time, he gets stuck as follows:

  • Disable user <A> link
  • We get a WebView.shouldStartLoadWithRequest callback
  • We get a WebView.webViewDidStartLoad callback
  • nothing happens after that

The screen still shows the original page with a link to it. We can break the trap in two ways:

  • Rotate device
  • Touch screen

At this point, the page will complete the download immediately.

We used the recipe from here:

Javascript console.log () on iOS UIWebView

to give us some idea about loading the page. We put the javascript-side material directly in the first script file that we load on the page, and it does not print its message until we get around the workaround.

So, it looks like he's stuck somewhere between the start of the page loading and is starting to evaluate the material on the page.

We tried a number of workflows, none of which helped:

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

Any idea what we can do wrong?

+4
source share
2 answers

You can use gdb in Xcode to debug the problem. I think canidates for messages that may have breakpoints:

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

I would also add a break in any UIViewController showing your UIWebView for:

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

Then you can go through and hopefully catch what's wrong with your UIWebView subclass.

If you don’t want to add breakpoints, you can simply launch the application in the Xcode debugger and click the “pause” button above the console window when your application stops responding at startup.

GDB Pause Execution Button

It's hard to understand what happens without any code, but I'm sure Xcode can help you quickly find the problem.

Good luck

+2
source

Found a solution for this strange behavior, at least in my case.

In my application, I created a subclass of UIWebView. I know that the apple documentation states that you should not subclass UIWebView. But it is "necessary" in my application.

The problem was that I was overwriting scrollViewDidEndDragging: willDecelerate: without calling super.

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

becomes

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

Now it always loads the website when clicking on the html link.

0
source

Source: https://habr.com/ru/post/1379522/


All Articles