iOS WebView WTF崩溃

时间:2016-10-21 13:21:35

标签: ios uiwebview crash

有人遇到下面的崩溃吗?

0 WebKitLegacy 0x000000018f766884 std::__1::unique_ptr<WTF::Function<void ()>, std::__1::default_delete<WTF::Function<void ()> > > WTF::MessageQueue<WTF::Function<void ()> >::waitForMessageFilteredWithTimeout<WTF::MessageQueue<WTF::Function<void ()> >::waitForMessage()::'lambda'(WTF::Function<void ()> const&)>(WTF::MessageQueueWaitResult&, WTF::MessageQueue<WTF::Function<void ()> >::waitForMessage()::'lambda'(WTF::Function<void ()> const&)&&, double) + 192
1 WebKitLegacy 0x000000018f765e68 WebCore::StorageThread::threadEntryPoint() + 68
5 JavaScriptCore 0x000000018dabf35c WTF::threadEntryPoint(void*) + 212
6 JavaScriptCore 0x000000018dabf26c WTF::wtfThreadEntryPoint(void*) + 24
8 libsystem_pthread.dylib 0x0000000188c9f860 __pthread_body + 240
9 libsystem_pthread.dylib 0x0000000188c9f770 __pthread_body
10 libsystem_pthread.dylib 0x0000000188c9cdbc start_wqthread + 0

3 个答案:

答案 0 :(得分:2)

最后,我发现此崩溃与localstorage线程有关。当我们在JavaScript中调用window.localStorage时,它会触发webkit创建一个localstorage线程,当所有UIWebView实例都被释放时,该线程将被破坏。事实上,localstorage线程将比UIWebView实例更晚被破坏,导致Wild指针崩溃。因此,您可以创建一个UIWebView实例,该实例执行" window.localstorage.setItem(x,x)"并且永远不会破坏它,或者你可以使用WKWebView。

答案 1 :(得分:0)

在离开视图之前停止加载webView并删除delegate

  

在发布已设置的UIWebView实例之前   委托,您必须首先将其委托属性设置为nil。这可以   用dealloc方法完成。

尝试将WebView的委托设置为nil并停止在ViewController的viewWillUnload方法中加载WebView:

- (void)viewWillUnload {

    [webView setDelegate:nil];
    [webView stopLoading];
}

答案 2 :(得分:0)

我通过创建静态UIWebView实例解决了此问题。

const user = require('../models');

当我在+ (void)load { if ([UIDevice isIOS10]) { static UIWebView *storageCrashFixWebView = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ storageCrashFixWebView = [[UIWebView alloc] initWithFrame:CGRectZero]; [storageCrashFixWebView loadHTMLString:@"<script>window.localStorage</script>" baseURL:nil]; }); } } 处设置符号断点时,使用std::__1::unique_ptr&lt;WTF::Function&lt;void ()&gt;, std::__1::default_delete&lt;WTF::Function&lt;void ()&gt; &gt; &gt; WTF::MessageQueue&lt;WTF::Function&lt;void ()&gt; &gt;::waitForMessageFilteredWithTimeout&lt;WTF::MessageQueue&lt;WTF::Function&lt;void ()&gt; &gt;::waitForMessage()::'lambda'(WTF::Function&lt;void ()&gt; const&amp;)&gt;(WTF::MessageQueueWaitResult&amp;, WTF::MessageQueue&lt;WTF::Function&lt;void ()&gt; &gt;::waitForMessage()::'lambda'(WTF::Function&lt;void ()&gt; const&amp;)&amp;&amp;, double)的最后一个UIWebView被销毁时,它将断开。