2013-02-13 60 views
4

我一直在試圖弄清楚是什麼導致我的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 

回答

0

似乎你在後臺線程更新UI,在您的代碼中加入這一行,無論你正在更新你的UI,你是取在後臺線程數據:

dispatch_async(dispatch_get_main_queue(), ^{ 
        // Update data here 
}); 

只要你,而代碼認爲數據是存在的設備上,它的時間更新對應於新的數據,然後嘗試,並帶回主線程在行動UI。

希望它有幫助。

+1

感謝您花時間回覆。所以我的主要問題是我不確定後臺線程上的更新發生在哪裏。據我可以告訴所有通知正在主線程上發生。我曾嘗試設置斷點並記錄與UIWebView相關的每個函數。關於我剛剛丟失的後臺線程發生的網頁瀏覽問題,是否有一些常見的回調? – Rajusa 2013-02-14 16:17:04

+0

你有這種方法嗎? - (void)webViewDidFinishLoad:(UIWebView *)webView這可以告訴你webview已經完成加載,現在你可以將控件傳遞給主線程。 – 2013-02-14 18:11:26

+0

或者在你的代碼中執行此操作,並測試它是否工作正常 - //創建並分配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