iOS bugly crash 问题分析

iOS Crash问题汇总

1. 线程问题

  1. bugly上报问题:_WebThreadLock() 问题
    iOS bugly crash 问题分析
在这里插入代码片

问题分析:是没有在主线程中刷新WebView reloadData

最近的專案中,需要在UITableView中放UIWebView,webview本身會有webthreadlock,因為他在reload之後是UI的re-render,會被要求一定要在mainthread上面跑。UI繪製一定要在mainthread上[webViewreload];但是當webview要reload時,tableview也正在reload,webviewreload所使用的WebThreadLock就會被推到secondarythread,就會導致crash而

最近的專案中,需要在UITableView中放UIWebView,web view 本身會有 web thread lock,因為他在 reload 之後是 UI 的 re-render,會被要求一定要在 main thread 上面跑。
UI 繪製一定要在 main thread 上
[webView reload];
但是當 web view 要 reload 時, table view 也正在 reload,web view reload 所使用的WebThreadLock就會被推到 secondary thread ,就會導致 crash 而跳出以下的錯誤訊息:
bool _WebTryThreadLock(bool), 0x115504830: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now…1 0x108412aa8 WebThreadLock2 0x102579e77 -[UIWebView reload]
解法
強制讓[webView reload]一定要在 main thread 即可解決, call methodperformSelectorOnMainThread:withObject:waitUntilDone:指定要在 main thread 上執行的 method:
[webView performSelectorOnMainThread:@selector(reload) withObject:nil waitUntilDone:NO];
以上是在 iOS 中避免 WebThreadLock 造成 Crash的内容,更多 的内容,请您使用右上方搜索功能获取相关信息。

  1. xcode日志 只有_WebThreadLock 没有具体的错误原因,也没有定位到崩溃代码位置。crashlytics上有一下runloop相关信息
1  WebCore                        0x18d58b858 WebRunLoopLock(__CFRunLoopObserver*, unsigned long, void*) + 44

所以我猜测是不是项目中使用runloop出现了问题。全局查找,注册了所有的runloop,然后在测试 右滑关闭outlook界面,崩溃不出现了。注册代码

_timerLoop = [NSTimer timerWithTimeInterval:_durationTime target:self selector:@selector(timerScrollImage) userInfo:nil repeats:YES];
   [[NSRunLoop currentRunLoop] addTimer:_timerLoop forMode:NSDefaultRunLoopMode];
 //注册一下代码
 //  [[NSRunLoop currentRunLoop] runMode:UITrackingRunLoopMode beforeDate:[NSDate date]];

相关文章: