UIWeb 视图:Web 线程 EXC_BAD_ACCESS

UIWebview: WebThread EXC_BAD_ACCESS

我有一个非常简单的应用程序:使用 http://tv2.dk

显示网络视图

我正在使用故事板,添加了网络视图并在我的控制器上设置了 属性。为了简单起见,我没有设置委托。

在 viewDidLoad 中,我用 url 我想加载的 Web 视图调用

[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://tv2.dk"]]];

每次应用程序启动时都会由于网络线程工作程序中的某些错误而崩溃,请参阅此转储。

libobjc.A.dylib`objc_msgSend:
0x1954f7bc0:  cmp    x0, #0
0x1954f7bc4:  b.le   0x1954f7c30               ; objc_msgSend + 112
0x1954f7bc8:  ldr    x13, [x0]
0x1954f7bcc:  and    x9, x13, #0x1fffffff8
0x1954f7bd0:  ldp    x10, x11, [x9, #16]
0x1954f7bd4:  and    w12, w1, w11
0x1954f7bd8:  add    x12, x10, x12, lsl #4
0x1954f7bdc:  ldp    x16, x17, [x12]
0x1954f7be0:  cmp    x16, x1
0x1954f7be4:  b.ne   0x1954f7bec               ; objc_msgSend + 44
0x1954f7be8:  br     x17
0x1954f7bec:  cbz    x16, 0x1954f7d80          ; _objc_msgSend_uncached_impcache
0x1954f7bf0:  cmp    x12, x10
0x1954f7bf4:  b.eq   0x1954f7c00               ; objc_msgSend + 64
0x1954f7bf8:  ldp    x16, x17, [x12, #-16]!
0x1954f7bfc:  b      0x1954f7be0               ; objc_msgSend + 32
0x1954f7c00:  add    x12, x12, w11, uxtw #4
0x1954f7c04:  ldp    x16, x17, [x12]
0x1954f7c08:  cmp    x16, x1
0x1954f7c0c:  b.ne   0x1954f7c14               ; objc_msgSend + 84
0x1954f7c10:  br     x17
0x1954f7c14:  cbz    x16, 0x1954f7d80          ; _objc_msgSend_uncached_impcache
0x1954f7c18:  cmp    x12, x10
0x1954f7c1c:  b.eq   0x1954f7c28               ; objc_msgSend + 104
0x1954f7c20:  ldp    x16, x17, [x12, #-16]!
0x1954f7c24:  b      0x1954f7c08               ; objc_msgSend + 72
0x1954f7c28:  mov    x2, x9
0x1954f7c2c:  b      0x1954e1e70               ; objc_msgSend_corrupt_cache_error
0x1954f7c30:  b.eq   0x1954f7c48               ; objc_msgSend + 136
0x1954f7c34:  adrp   x10, 18278
0x1954f7c38:  add    x10, x10, #1904
0x1954f7c3c:  lsr    x11, x0, #60
0x1954f7c40:  ldr    x9, [x10, x11, lsl #3]
0x1954f7c44:  b      0x1954f7bd0               ; objc_msgSend + 16
0x1954f7c48:  movz   x1, #0
0x1954f7c4c:  movi   d0, #0000000000000000
0x1954f7c50:  movi   d1, #0000000000000000
0x1954f7c54:  movi   d2, #0000000000000000
0x1954f7c58:  movi   d3, #0000000000000000
0x1954f7c5c:  ret    

违规行

0x1954f7bd0:  ldp    x10, x11, [x9, #16]

在此处查看完整的源代码:https://bitbucket.org/styrken/ios-webview-crash

我已经在多个设备上尝试过 运行 这段代码,但都崩溃了。

来自@RasmusStyrk 上面的评论

I have found out that with using NSZombie's, i got the following crash message: WebviewCrash[4598:956679] *** -[UIViewAnimationState release]: message sent to deallocated instance 0x1707c5370. To fix this i had to turn off animations in UIVIew using [UIView setAnimationsEnabled:NO]; and now it works. It seems like a bug in iOS8. –

我们也遇到过它会随机崩溃的情况,设置 [UIView setAnimationsEnabled:NO] 是唯一可以完全缓解此问题的方法!

就我而言,我犯了一个愚蠢的错误,忘记在加载资源之前将 WKWebView 添加到视图层次结构中。

Thread EXC_BAD_ACCESS 说明了一切。 UIWebView 喜欢从主线程调用。尝试将您的代码如下所示:

dispatch_async(dispatch_get_main_queue(), ^{
 //send webview a message 
 [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://tv2.dk"]]];
});