UIWebview gets stuck with the following message in console

无人久伴 提交于 2019-11-29 02:29:31

问题


UIWebview gets stuck with the following message in console.

void SendDelegateMessage(NSInvocation*): delegate (webView:didFinishLoadForFrame:)   
failed to return after waiting 10 seconds. main run loop mode: kCFRunLoopDefaultMode

anyone knows what this is??


回答1:


Are you using any Javascript on the page you are loading?

Specifically, are you using the method

- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script

As the docs state the following

JavaScript execution time is limited to 10 seconds for each top-level entry point. If your script executes for more than 10 seconds, the web view stops executing the script

And this seems to tie in with the error message you are seeing in the console




回答2:


FWIW, it looks like my particular timeout was occurring due to a javascript error in rare scenarios. You might try wrapping your JS in a try/catch or improving it to be more error-tolerant.


More details: I was using the following JS string:

NSString* js = @"document.getElementById(\"main\").offsetHeight";
int height = [[_web_view stringByEvaluatingJavaScriptFromString:js] intValue];

I knew that this UIWebView problem could happen if the web view was not fully loaded (eg. JS called before the webViewDidFinishLoad: method, so I guessed that perhaps the "main" object was missing. Thus, I modified my JS to the following and it worked:

NSString* js = @"document.getElementById(\"main\") ? document.getElementById(\"main\").offsetHeight : -1";



回答3:


Below code snippet worked for me.

if(!webview.isLoading)
{
   // update your code.
}



回答4:


Try to use WKWebView instead of UIWebView.this works for me.

In my case, I try to use UIWebView to open local PDF.some of the PDF may contain some JS code.then I run into this problem.

After using WKWebView, everything works just perfect

Apple also recommends you to use WKWebView if your app that runs in iOS 8 and later



来源:https://stackoverflow.com/questions/6489601/uiwebview-gets-stuck-with-the-following-message-in-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!