我在一些屏幕中使用了 UIWebViews,因为我需要一个完美的 Html 文本解析。
根据崩溃报告,这些屏幕上发生了大量崩溃,称为 WTF 崩溃。这是崩溃的痕迹
Crashed: WebThread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x00000000bbadbeef
Thread : Crashed: WebThread
0 JavaScriptCore 0x184fd2710 WTFCrash + 72
1 JavaScriptCore 0x184fd2708 WTFCrash + 64
2 WebCore 0x1852b7d78 <redacted> + 362
3 WebCore 0x1852b7bec <redacted> + 44
4 CoreFoundation 0x1817d8588 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
5 CoreFoundation 0x1817d632c __CFRunLoopDoObservers + 372
6 CoreFoundation 0x1817d6674 __CFRunLoopRun + 696
7 CoreFoundation 0x181705680 CFRunLoopRunSpecific + 384
8 WebCore 0x1852b5998 <redacted> + 456
9 libsystem_pthread.dylib 0x18148bb28 <redacted> + 156
10 libsystem_pthread.dylib 0x18148ba8c _pthread_start + 154
11 libsystem_pthread.dylib 0x181489028 thread_start + 4
此次崩溃与操作系统版本或设备无关。
我也没有对使用 UIWebView 做任何花哨的事情。它像所有其他组件一样被添加到 nib 中,在实现文件中我像下面这样使用它
self.webView.scrollView.scrollEnabled = NO;
self.webView.scrollView.bounces = NO;
self.webView.opaque = NO;
self.webView.backgroundColor = [UIColor clearColor];
self.webView.delegate = self;
[self.webView loadHTMLString:htmlString baseURL:nil];
关于如何解决 WTF 崩溃有什么建议吗?
编辑:这是 htmlString 的样子
Printing description of htmlString:
<html><body style="font-family:HelveticaNeue; font-size:10; background-color:#E5E4E4; text-align:left; color:#696969 ">test string</body></html>
最佳答案
我不知道您是如何创建 UIWebView 的。但是我遇到了 WTFCrash 的类似问题,我能够通过确保在主线程上创建 UIWebView 来解决它:
- (void)createWebView{
if (![NSThread isMainThread]) {
dispatch_async(dispatch_get_main_queue(), ^{
[self createWebView];
});
return;
}
self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
//Rest of my code
}
关于ios - 奇怪的 iOS UIWebView 崩溃称为 WTF 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35128579/