我在基于Swift 3的应用程序上遇到了一个奇怪的问题,我正在尝试找出最佳解决方案。基于崩溃日志,看起来Springboard正在中止,因为Watchdog框架发现一个过程需要很长时间才能删除。令我感到困惑的是,通常情况下,当有网络电话或需要花费大量时间处理的事情(比平时更多)时,这种情况会发生在我身上。
在我的例子中,我只是处理视频并从场景中移除观察者。删除观察者的代码行似乎导致应用程序崩溃,它只会执行几次。我的问题是 - 通知中心观察员逻辑是否能够触发像这样的看门狗错误?如果是这样,我该怎么办呢?
以下是错误的代码行:
if((videoPlayer) != nil){
videoPlayer.pause();
videoPlayer.removeFromParent();
videoPlayer = nil;
NotificationCenter.default.removeObserver(currentScene); //line 176 referenced in log below
}
这是崩溃日志:
编辑现在使用所有主题。
Date/Time: 2017-06-29 08:46:28.3634 -0400
Launch Time: 2017-06-28 10:00:59.4686 -0400
OS Version: iPhone OS 10.3.2 (14F89)
Report Version: 104
Exception Type: EXC_CRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Termination Reason: Namespace SPRINGBOARD, Code 0x8badf00d
Triggered by Thread: 0
Filtered syslog:
None found
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x000000018b6b58e8 __ulock_wait + 8
1 libdispatch.dylib 0x000000018b58577c _dispatch_ulock_wait + 48
2 libdispatch.dylib 0x000000018b5858a4 _dispatch_thread_event_wait_slow + 36
3 libdispatch.dylib 0x000000018b5834f0 _dispatch_barrier_sync_f_slow + 236
4 MediaToolbox 0x00000001938ad4c8 FigVisualContextInvalidate + 156
5 AVFoundation 0x000000019414dd70 -[AVPlayerItemVideoOutput dealloc] + 164
6 SpriteKit 0x000000019be40998 SKCVideoNode::~SKCVideoNode() + 88
7 SpriteKit 0x000000019be40a1c SKCVideoNode::~SKCVideoNode() + 12
8 SpriteKit 0x000000019be07bc4 -[SKNode dealloc] + 48
9 coversapp 0x00000001000685f8 removeVideo() -> () (media.swift:176)
10 coversapp 0x0000000100046150 MainMenuScene.videoDone() -> () (MainMenuScene.swift:123)
11 coversapp 0x00000001000418ac MainMenuScene.touchesBegan(Set<UITouch>, with : UIEvent?) -> () (MainMenuScene.swift:60)
12 coversapp 0x0000000100041954 @objc MainMenuScene.touchesBegan(Set<UITouch>, with : UIEvent?) -> () (MainMenuScene.swift:0)
13 SpriteKit 0x000000019bde8730 -[SKView touchesBegan:withEvent:] + 844
14 UIKit 0x000000019281917c -[UIWindow _sendTouchesForEvent:] + 1948
15 UIKit 0x0000000192814728 -[UIWindow sendEvent:] + 3192
16 UIKit 0x00000001927e533c -[UIApplication sendEvent:] + 340
17 UIKit 0x0000000192fdf014 __dispatchPreprocessedEventFromEventQueue + 2400
18 UIKit 0x0000000192fd9770 __handleEventQueue + 4268
19 UIKit 0x0000000192fd9b9c __handleHIDEventFetcherDrain + 148
20 CoreFoundation 0x000000018c66942c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
21 CoreFoundation 0x000000018c668d9c __CFRunLoopDoSources0 + 540
22 CoreFoundation 0x000000018c6669a8 __CFRunLoopRun + 744
23 CoreFoundation 0x000000018c596da4 CFRunLoopRunSpecific + 424
24 GraphicsServices 0x000000018e000074 GSEventRunModal + 100
25 UIKit 0x000000019284a058 UIApplicationMain + 208
26 coversapp 0x000000010006a4ac main (AppDelegate.swift:12)
27 libdyld.dylib 0x000000018b5a559c start + 4
Thread 1 name: com.apple.uikit.eventfetch-thread
Thread 1:
0 libsystem_kernel.dylib 0x000000018b697224 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x000000018b69709c mach_msg + 72
2 CoreFoundation 0x000000018c668e90 __CFRunLoopServiceMachPort + 192
3 CoreFoundation 0x000000018c666ae4 __CFRunLoopRun + 1060
4 CoreFoundation 0x000000018c596da4 CFRunLoopRunSpecific + 424
5 Foundation 0x000000018d0b0d74 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 304
6 Foundation 0x000000018d0d1b44 -[NSRunLoop(NSRunLoop) runUntilDate:] + 96
7 UIKit 0x00000001931d46a8 -[UIEventFetcher threadMain] + 136
8 Foundation 0x000000018d1ae2d8 __NSThread__start__ + 996
9 libsystem_pthread.dylib 0x000000018b77d68c _pthread_body + 240
10 libsystem_pthread.dylib 0x000000018b77d59c _pthread_body + 0
11 libsystem_pthread.dylib 0x000000018b77acb4 thread_start + 4
Thread 2 name: AVAudioSession Notify Thread
Thread 2:
0 libsystem_kernel.dylib 0x000000018b697224 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x000000018b69709c mach_msg + 72
2 CoreFoundation 0x000000018c668e90 __CFRunLoopServiceMachPort + 192
3 CoreFoundation 0x000000018c666ae4 __CFRunLoopRun + 1060
4 CoreFoundation 0x000000018c596da4 CFRunLoopRunSpecific + 424
5 AVFAudio 0x00000001a6204540 GenericRunLoopThread::Entry(void*) + 164
6 AVFAudio 0x00000001a622a814 CAPThread::Entry(CAPThread*) + 84
7 libsystem_pthread.dylib 0x000000018b77d68c _pthread_body + 240
8 libsystem_pthread.dylib 0x000000018b77d59c _pthread_body + 0
9 libsystem_pthread.dylib 0x000000018b77acb4 thread_start + 4
Thread 3 name: com.apple.coreaudio.AQClient
Thread 3:
0 libsystem_kernel.dylib 0x000000018b697224 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x000000018b69709c mach_msg + 72
2 CoreFoundation 0x000000018c668e90 __CFRunLoopServiceMachPort + 192
3 CoreFoundation 0x000000018c666ae4 __CFRunLoopRun + 1060
4 CoreFoundation 0x000000018c596da4 CFRunLoopRunSpecific + 424
5 AudioToolbox 0x000000018f61a9fc GenericRunLoopThread::Entry(void*) + 164
6 AudioToolbox 0x000000018f7ee4bc CAPThread::Entry(CAPThread*) + 84
7 libsystem_pthread.dylib 0x000000018b77d68c _pthread_body + 240
8 libsystem_pthread.dylib 0x000000018b77d59c _pthread_body + 0
9 libsystem_pthread.dylib 0x000000018b77acb4 thread_start + 4
Thread 4 name: Dispatch queue: FigVisualContext <0x170191fa0> image auto prune queue
Thread 4:
0 libsystem_kernel.dylib 0x000000018b6b58e8 __ulock_wait + 8
1 libdispatch.dylib 0x000000018b58577c _dispatch_ulock_wait + 48
2 libdispatch.dylib 0x000000018b5858a4 _dispatch_thread_event_wait_slow + 36
3 libdispatch.dylib 0x000000018b5834f0 _dispatch_barrier_sync_f_slow + 236
4 MediaToolbox 0x0000000193950f78 itemremotevc_copyCorrespondingItemForItem + 144
5 MediaToolbox 0x0000000193953368 itemremotevc_copyImageForTimeCallback + 192
6 MediaToolbox 0x00000001938ae2d4 FigVisualContextCopyImageForTime2 + 208
7 MediaToolbox 0x00000001938ad96c figVisualContextAutoPrune + 220
8 libdispatch.dylib 0x000000018b5729a0 _dispatch_client_callout + 16
9 libdispatch.dylib 0x000000018b57f604 _dispatch_continuation_pop + 448
10 libdispatch.dylib 0x000000018b58bc1c _dispatch_source_latch_and_call + 204
11 libdispatch.dylib 0x000000018b5748a0 _dispatch_source_invoke + 804
12 libdispatch.dylib 0x000000018b580964 _dispatch_queue_serial_drain + 560
13 libdispatch.dylib 0x000000018b5762cc _dispatch_queue_invoke + 884
14 libdispatch.dylib 0x000000018b582a50 _dispatch_root_queue_drain + 540
15 libdispatch.dylib 0x000000018b5827d0 _dispatch_worker_thread3 + 124
16 libsystem_pthread.dylib 0x000000018b77b100 _pthread_wqthread + 1096
17 libsystem_pthread.dylib 0x000000018b77acac start_wqthread + 4
Thread 5 name: Dispatch queue: com.apple.coremedia.visualContextSyncQueue
Thread 5:
0 libsystem_kernel.dylib 0x000000018b6b4e1c __psynch_cvwait + 8
1 libsystem_pthread.dylib 0x000000018b77c814 _pthread_cond_wait + 640
2 CoreMedia 0x000000018ef940dc WaitOnCondition + 16
3 CoreMedia 0x000000018ef94024 FigSemaphoreWaitRelative + 168
4 CoreMedia 0x000000018f03e5dc FigReadWriteLockLockForWrite + 84
5 MediaToolbox 0x00000001938adcb0 FigVisualContextSetProducerCallbacks + 56
6 MediaToolbox 0x0000000193952e94 __itemremote_Invalidate_block_invoke + 92
7 libdispatch.dylib 0x000000018b5729a0 _dispatch_client_callout + 16
8 libdispatch.dylib 0x000000018b57fee0 _dispatch_barrier_sync_f_invoke + 84
9 MediaToolbox 0x000000019384bbcc itemremote_Invalidate + 348
10 CoreFoundation 0x000000018c5961d0 __CFSetApplyFunction_block_invoke + 24
11 CoreFoundation 0x000000018c596010 CFBasicHashApply + 132
12 CoreFoundation 0x000000018c595f40 CFSetApplyFunction + 224
13 MediaToolbox 0x000000019386b7b8 playerremote_Invalidate + 192
14 MediaToolbox 0x00000001938f219c playerasync_InvalidateOnQueue + 220
15 libdispatch.dylib 0x000000018b5729a0 _dispatch_client_callout + 16
16 libdispatch.dylib 0x000000018b580ad4 _dispatch_queue_serial_drain + 928
17 libdispatch.dylib 0x000000018b5762cc _dispatch_queue_invoke + 884
18 libdispatch.dylib 0x000000018b580fa8 _dispatch_queue_override_invoke + 344
19 libdispatch.dylib 0x000000018b582a50 _dispatch_root_queue_drain + 540
20 libdispatch.dylib 0x000000018b5827d0 _dispatch_worker_thread3 + 124
21 libsystem_pthread.dylib 0x000000018b77b100 _pthread_wqthread + 1096
22 libsystem_pthread.dylib 0x000000018b77acac start_wqthread + 4