iOS - 在_WebTryThreadLock中确定崩溃的原因(来自崩溃报告)
问题描述:
我一直在试图弄清楚是什么导致我的iOS应用程序中的顶级崩溃之一。它看起来像是在后台线程上发生了一些布局,导致它崩溃。有什么方法可以确定我可能在做什么触发这个重新布局?当我的应用程序被带回到前台时,我从堆栈中假定它与UIWebView相关。iOS - 在_WebTryThreadLock中确定崩溃的原因(来自崩溃报告)
该主题上的其他stackoverflow线程似乎提到像在后台线程上触发表重新加载的东西。据我所见,所有的webView委托方法都会在主线程中调用。有没有一些情况下,这是不正确的,还是有一些其他方法被调用后台线程,我只是不知道?
Web主题 - 崩溃。
0 WebCore _WebTryThreadLock(bool) + 297
1 WebCore _WebTryThreadLock(bool) + 288
2 WebCore WebThreadLock + 66
3 UIKit -[UIWebDocumentView(UIWebDocumentViewTextSelecting) selectionBaseWritingDirection] + 10
4 UIKit -[UITextField _currentTextAlignment] + 86
5 UIKit -[UITextField _showsClearButtonWhenNonEmpty:] + 58
6 UIKit -[UITextField _textRectForBounds:forEditing:] + 678
7 UIKit -[UITextField editingRectForBounds:] + 52
8 UIKit -[UITextField editRect] + 70
9 UIKit -[UITextField layoutSubviews] + 1320
10 UIKit -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 258
11 QuartzCore -[CALayer layoutSublayers] + 214
12 QuartzCore CA::Layer::layout_if_needed(CA::Transaction*) + 460
13 QuartzCore CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16
14 QuartzCore CA::Context::commit_transaction(CA::Transaction*) + 238
15 QuartzCore CA::Transaction::commit() + 316
16 QuartzCore CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 60
17 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
18 CoreFoundation __CFRunLoopDoObservers + 276
19 CoreFoundation CFRunLoopRunSpecific + 394
20 CoreFoundation CFRunLoopRunInMode + 104
21 WebCore RunWebThread(void*) + 444
22 libsystem_c.dylib pthread_start + 308
主 - 主题
0 libsystem_kernel.dylib __psynch_mutexwait + 24
1 libsystem_c.dylib pthread_mutex_lock + 392
2 WebCore _WebTryThreadLock(bool) + 336
3 WebCore WebThreadLock + 66
4 WebKit -[WebDatabasePauser applicationWillEnterForeground] + 16
5 CoreFoundation _CFXNotificationPost + 1426
6 Foundation -[NSNotificationCenter postNotificationName:object:userInfo:] + 72
7 UIKit -[UIApplication _sendWillEnterForegroundCallbacks] + 154
8 UIKit -[UIApplication _handleApplicationResumeEvent:] + 1094
9 UIKit -[UIApplication handleEvent:withNewEvent:] + 1292
10 UIKit -[UIApplication sendEvent:] + 72
11 UIKit _UIApplicationHandleEvent + 6154
12 GraphicsServices _PurpleEventCallback + 590
13 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
14 CoreFoundation __CFRunLoopDoSources0 + 212
15 CoreFoundation __CFRunLoopRun + 646
16 CoreFoundation CFRunLoopRunSpecific + 356
17 CoreFoundation CFRunLoopRunInMode + 104
18 GraphicsServices GSEventRunModal + 74
19 UIKit UIApplicationMain + 1120
20 AppName main.m line 23
答
似乎你在后台线程更新UI,在您的代码中加入这一行,无论你正在更新你的UI,你是取在后台线程数据:
dispatch_async(dispatch_get_main_queue(), ^{
// Update data here
});
只要你,而代码认为数据是存在的设备上,它的时间更新对应于新的数据,然后尝试,并带回主线程在行动UI。
希望它有帮助。
感谢您花时间回复。所以我的主要问题是我不确定后台线程上的更新发生在哪里。据我可以告诉所有通知正在主线程上发生。我曾尝试设置断点并记录与UIWebView相关的每个函数。关于我刚刚丢失的后台线程发生的网页浏览问题,是否有一些常见的回调? – Rajusa 2013-02-14 16:17:04
你有这种方法吗? - (void)webViewDidFinishLoad:(UIWebView *)webView这可以告诉你webview已经完成加载,现在你可以将控件传递给主线程。 – 2013-02-14 18:11:26
或者在你的代码中执行此操作,并测试它是否工作正常 - //创建并分配UIWebView对象,我称之为webViewObj NSURL * webURLObj = [NSURL URLWithString:url]; dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0); dispatch_async(队列,^ { 的NSURLRequest *请求= [的NSURLRequest requestWithURL:webURLObj]; [webViewObj的loadRequest:请求]; dispatch_sync(dispatch_get_main_queue(),^ { [webViewObj释放]; } ); }); – 2013-02-14 18:11:43