iOS应用程序崩溃与cfrunloop_is_calling_out_to_an_observer_callback_function

Fab*_*cci 8 xcode ios

在运行我的应用程序时,我偶尔会遇到这个崩溃似乎与我的代码没有任何关系.它是什么以及我如何避免它?

线程0名:调度队列:com.apple.main线程线程0毁损:0 libsystem_kernel.dylib 0x000000018fc4c16c mach_msg_trap + 8 1 libsystem_kernel.dylib
0x000000018fc4bfdc mach_msg + 72 2 AudioToolbox
0x0000000193c8bcdc ASClient_AudioSessionSetActiveWithFlags + 132 3
AudioToolbox 0x0000000193c6c7f4 AudioSessionSetActive_Priv + 360 4 AVFAudio
0x00000001aa46bf8c - [AVAudioSession setActive:withOptions:error:] + 84 5 Jam Session 0x00000001000d41b8 0x1000b0000 + 147896 6 Jam Session 0x00000001000d53fc 0x1000b0000 + 152572 7 UIKit
0x0000000196ae90ec - [UIViewController loadViewIfRequired] + 1056 8
UIKit 0x0000000196ba2cdc - [UINavigationController _layoutViewController:] + 72 9 UIKit 0x0000000196ba2bb4 - [UINavigationController _updateScrollViewFromViewController:toViewController:] + 416 10 UIKit 0x0000000196ba1efc - [UINavigationController _startTransition:fromViewController:toViewController:] + 140 11 UIKit 0x0000000196ba1948 - [UINavigationController _startDeferredTransitionIfNeeded:] + 8 56 12 UIKit 0x0000000196ba14fc - [UINavigationController viewWillLayoutSubviews] + 64 13 UIKit 0x0000000196ba1460 - [UILayoutContainerView layoutSubviews] + 188 14 UIKit 0x0000000196ae625c - [UIView(CALayerDelegate)layoutSublayersOfLayer:] + 1196 15 QuartzCore 0x0000000193fad2c8 - [CALayer layoutSublayers] + 148 16 QuartzCore
0x0000000193fa1fa4 CA: :Layer :: layout_if_needed(CA :: Transaction*)+ 292 17 QuartzCore 0x0000000193fa1e64 CA :: Layer :: layout_and_display_if_needed(CA :: Transaction*)+ 32 18 QuartzCore 0x0000000193f1eb20 CA :: Context :: commit_transaction(CA :: Transaction*) + 252 19 QuartzCore 0x0000000193f45f8c CA ::交易::提交()+ 512 20 QuartzCore
0x0000000193f469ac CA ::交易:: observer_callback(__ CFRunLoopObserver*,无符号长,无效*)+ 120 21的CoreFoundation
0x0000000190c4a7dc __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION
+ 32个22的CoreFoundation 0x0000000190c4840c __CFRunLoopDoObservers + 372 23 CoreFoundation 0x0000000190b77068 CFRunLoopRunSpecific + 476 24 U IKit
0x0000000196b542ec - [UIApplication _run] + 608 25 UIKit
0x0000000196b4f070 UIApplicationMain + 208 26 Jam Session
0x00000001000c36d4 0x1000b0000 + 79572 27 libdyld.dylib
0x000000018fb585b8 start + 4

Ann*_*pta 0

使用时会发生此崩溃NSNotificationCenter

您向已释放的对象注册了通知观察者,但未删除该观察者。因此,当它尝试调用选择器时,它会崩溃。

如果您使用ViewController某种类型,您可以添加

[[NSNotificationCenter defaultCenter] removeObserver:self name:@"Notification" object:nil];
Run Code Online (Sandbox Code Playgroud)

viewWillDisappear

如果它不是 ViewController,您可以使用它-(void) dealloc来取消注册观察者。

如果您进一步调试以准确找出崩溃的根源。在断点选项卡中放置异常断点并运行应用程序,进行临时测试并查看是否会崩溃。

这应该有效..

干杯!