iOS - 确定 _WebTryThreadLock 中的崩溃原因(来自崩溃报告)

标签 ios crash crash-reports

我一直在努力找出是什么导致了我的 iOS 应用程序中最严重的崩溃之一。看起来后台线程上发生了一些布局,导致它崩溃。有什么方法可以确定我可能正在做的事情会触发此重新布局吗?当我的应用程序被带回前台时,我从堆栈中假设它与 UIWebView 相关。

关于该主题的其他 stackoverflow 线程似乎提到了诸如在后台线程上触发表重新加载之类的事情。据我所知,所有 webView 委托(delegate)方法都在主线程上被调用。在某些情况下这不是真的,或者是否有一些其他方法在后台线程上被调用而我只是不知道?

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,然后尝试恢复主线程的运行。

希望对您有所帮助。

关于iOS - 确定 _WebTryThreadLock 中的崩溃原因(来自崩溃报告),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14860180/

相关文章:

ios - 自定义 UINavigationBar 不支持给定的高度

ios - Swift 如何在标签中的文本周围添加背景颜色?

ios - iCloud - 如何更新 UIDocument 文件?

c# - .net mvc5 应用程序在实例化 View 模型时偶尔会无明显原因地因 ..ctor 引用而崩溃

ios - SwiftUI:如何在物理配置的设备上预览 View ?

android - Android Studio在应用程序内部重新加载应用程序

ios - 使用大量内存的动画iOS7

iphone - 如何解释崩溃报告?

iphone - 没有崩溃的崩溃日志?

android - 使用 AppCenter,我能否将用户数据添加到未处理的崩溃报告中?