我使用UIWebView在我的iOS应用程序中嵌入YouTube HTML播放器,有时当应用程序从后台进入前台时(视频正在播放),应用程序刚刚冻结,我得到0x000000008badf00d崩溃。
OS Version: iOS 7.1.1 (11D201)
Report Version: 104
Exception Type: 00000020
Exception Codes: 0x000000008badf00d
Highlighted Thread: 0
Application Specific Information:
com.myapp.myapp failed to resume in time
Elapsed total CPU time (seconds): 6.460 (user 6.460, system 0.000), 27% CPU
Elapsed application CPU time (seconds): 3.069, 13% CPU
Thread 0:
0 libsystem_kernel.dylib 0x39911f9c __psynch_mutexwait + 24
1 libsystem_pthread.dylib 0x3997b298 _pthread_mutex_lock_contended + 48
2 libsystem_pthread.dylib 0x39977d36 _pthread_mutex_lock + 258
3 WebCore 0x36e2f190 _WebTryThreadLock(bool) + 40
4 WebCore 0x36e2ffb8 WebThreadLock + 76
5 WebCore 0x36e6b962 -[TileLayer layoutSublayers] + 14
6 QuartzCore 0x3106db3a CA::Layer::layout_if_needed(CA::Transaction*) + 346
7 QuartzCore 0x3106d9cc CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 12
8 QuartzCore 0x3106d3e0 CA::Context::commit_transaction(CA::Transaction*) + 224
9 QuartzCore 0x3106d1f2 CA::Transaction::commit() + 310
10 AVFoundation 0x2da4fb60 -[AVPlayerLayer _updateSubtitles:forceRender:] + 696
11 AVFoundation 0x2da500a8 -[AVPlayerLayer layerDidBecomeVisible:] + 200
12 QuartzCore 0x3106bbf4 CA::Layer::mark_visible(CA::Transaction*, bool) + 80
13 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
14 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
15 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
16 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
17 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
18 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
19 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
20 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
21 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
22 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
23 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
24 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
25 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
26 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
27 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
28 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
29 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
30 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
31 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
32 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
33 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
34 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
35 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
36 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
37 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
38 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
39 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
40 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
41 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
42 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
43 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
44 QuartzCore 0x3106bc30 CA::Layer::mark_visible(CA::Transaction*, bool) + 140
45 QuartzCore 0x3106cb82 CA::Layer::set_visible(unsigned int) + 346
46 QuartzCore 0x3106c9e6 CA::Context::set_layer(void const*) + 134
47 UIKit 0x313feab2 -[UIWindow _createContext] + 1138
48 UIKit 0x316572a4 _UIWindowUpdateVisibleContextOrder + 172
49 UIKit 0x31657158 +[UIWindow _prepareWindowsPassingTestForAppResume:] + 12
50 UIKit 0x315fc534 -[UIApplication _handleApplicationResumeEvent:] + 72
51 UIKit 0x313fb60e -[UIApplication handleEvent:withNewEvent:] + 1878
52 UIKit 0x313fadf4 -[UIApplication sendEvent:] + 68
53 UIKit 0x3145f400 _UIApplicationHandleEvent + 612
54 GraphicsServices 0x33a68b52 _PurpleEventCallback + 606
55 GraphicsServices 0x33a6873a PurpleEventCallback + 30
56 CoreFoundation 0x2eb91844 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 32
57 CoreFoundation 0x2eb917de __CFRunLoopDoSource1 + 342
58 CoreFoundation 0x2eb8ffaa __CFRunLoopRun + 1402
59 CoreFoundation 0x2eafa764 CFRunLoopRunSpecific + 520
60 CoreFoundation 0x2eafa546 CFRunLoopRunInMode + 102
61 GraphicsServices 0x33a676ce GSEventRunModal + 134
62 UIKit 0x3145988c UIApplicationMain + 1132
63 myapp 0x0003ba0e main (main.m:14)
64 myapp 0x0003b9c4 start + 36
基本上我使用UIWebView
加载一个HTML文件与YouTube HTML播放器,并使用[webView stringByEvaluatingJavaScriptFromString: jsString]
来控制它(如loadVideoById()
, play()
, pause()
等)。还有一些机制,使应用程序可以在后台播放视频,大多数时候它工作得很好,这个崩溃只发生在它在后台播放几个视频,并试图进入前台,但很难重现。
似乎是webthread锁住了主线程,所以iOS杀死了我的应用,我已经研究了几个星期这个问题,但没有运气,欢迎任何建议
经过大量的实验,这个问题可以避免通过隐藏html播放器div标签与CSS当应用程序进入后台,然后再次显示它后,收到appDidBecomeActive事件。
我认为YouTube html播放器试图做一些UI相关的应用程序变得活跃,所以它可能会锁定主线程,得到0x000000008badf00d崩溃。
我在iOS 7上遇到过这个问题,只有当尝试在后台线程中使用包含YouTube iFrame播放器的HTML字符串调用loadHTMLString:baseURL:
时。将该调用与我所有其他UI调用一起移动到主线程似乎解决了这个问题。
我应该注意的是,我无法在iOS 8和9中重现这个问题,所以这也可能是一个WebKit错误,在后来的iOS更新中得到了修复。