xcode iOS 应用程序因 cfrunloop_is_calling_out_to_an_observer_callback_function 崩溃
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40056303/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS app crashing with cfrunloop_is_calling_out_to_an_observer_callback_function
提问by Fabrizio Bartolomucci
When running my app I occasionally get this crash that seems not to have anything with my code. What is it and how my I avert it?
在运行我的应用程序时,我偶尔会遇到这个似乎与我的代码没有任何关系的崩溃。它是什么以及我如何避免它?
Thread 0 name: Dispatch queue: com.apple.main-thread Thread 0 Crashed: 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:] + 856 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::Transaction::commit() + 512 20 QuartzCore
0x0000000193f469ac CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 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 UIKit
0x0000000196b542ec -[UIApplication _run] + 608 25 UIKit
0x0000000196b4f070 UIApplicationMain + 208 26 Jam Session
0x00000001000c36d4 0x1000b0000 + 79572 27 libdyld.dylib
0x000000018fb585b8 start + 4
线程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:错误:] + 84 5果酱会议0x00000001000d41b8 0x1000b0000 + 147896 6果酱会议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:] + 856 12 UIKit 0x0000000196ba14fc -[UINavigationControllerviewWillLayoutSubviews] + 64 13的UIKit 0x0000000196ba1460 - [UILayoutContainerView layoutSubviews] + 188 14的UIKit 0x0000000196ae625c - [UIView的(CALayerDelegate)layoutSublayersOfLayer:] + 1196 15 QuartzCore 0x0000000193fad2c8 - [CALayer的layoutSublayers] + 148 16 QuartzCore
0x0000000193fa1fa4 CA ::层:: layout_if_needed(CA ::Transaction*) + 292 17 QuartzCore 0x0000000193fa1e64 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32 18 QuartzCore 0x0000000193f1eb20 CA::Context::10c0f0c0000019340c0f2artzCA::commit_5c0f2artc3 :Transaction::commit() + 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的UIKit
0x0000000196b542ec - [UIApplication的_run] + 608 25的UIKit
0x0000000196b4f070 UIApplicationMain + 208 26 Jam Session
0x00000001000c36d4 0x1000b0000 + 79572 27 libdyld.dylib
0x000000018fb585545
回答by Declan Land
I came across this issue today after subclassing a UIView
. To resolve this I did the following:
我今天在子类化 a 后遇到了这个问题UIView
。为了解决这个问题,我做了以下事情:
- Add an Exception Breakpoint for all exceptions
- Enable Zombie Objects
- 为所有异常添加异常断点
- 启用僵尸对象
After viewing the thread stack on the left pane, I noticed something related to "key path" and "value".. then I realised that when creating my subclass, I'd created an IBInspectable
and updated this value in the storyboard. I later removed this and this is what caused the crash, because the class was still trying to set this value at runtime.
在左窗格中查看线程堆栈后,我注意到与“关键路径”和“值”相关的一些内容。然后我意识到在创建我的子类时,我IBInspectable
在故事板中创建了一个并更新了这个值。后来我删除了它,这就是导致崩溃的原因,因为该类仍在尝试在运行时设置此值。
So make sure to check your "User Defined Runtime Attributes".
所以一定要检查你的“用户定义的运行时属性”。
回答by Annie Gupta
This crash occurs when using NSNotificationCenter
使用时发生此崩溃 NSNotificationCenter
You registered a notification observer to an object that has been released and didn't removed the observer. So when it tries to call the selector it crashes.
您将通知观察者注册到已释放且未移除观察者的对象。因此,当它尝试调用选择器时,它会崩溃。
If you are using a ViewController
of some kind, you can add
如果您使用的ViewController
是某种类型,则可以添加
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"Notification" object:nil];
to the viewWillDisappear
到 viewWillDisappear
if it is not a ViewController you can use -(void) dealloc
to unregister the Observer.
如果它不是 ViewController,您可以-(void) dealloc
用来取消注册观察者。
In case you to debug further to exactly figure out the point of origin of crash. Put an exception breakpoint in the breakpoints tab and run the app, do casual testing and see if you get the crash.
如果您进一步调试以准确找出崩溃的原点。在断点选项卡中放置一个异常断点并运行应用程序,进行随意测试,看看是否会崩溃。
This should work..
这应该工作..
Cheers!
干杯!