是什么导致了这次崩溃?

发布于 2024-10-03 10:33:26 字数 2114 浏览 6 评论 0原文

最近,当使用 NSNotificationCenter 发布通知时,我遇到了由于找不到选择器而导致的崩溃。什么可能导致此错误?

我注意到在发布通知后没有调用任何用户代码,因此这在通知的接收端似乎不是问题。然而,什么可能导致 NSNotificationCenter 崩溃呢?

这是调用的堆栈跟踪:

0   libSystem.B.dylib               0x00078ac8 __kill + 8
1   libSystem.B.dylib               0x00078ab8 kill + 4
2   libSystem.B.dylib               0x00078aaa raise + 10
3   libSystem.B.dylib               0x0008d03a abort + 50
4   libstdc++.6.dylib               0x00044a20 __gnu_cxx::__verbose_terminate_handler() + 376
5   libobjc.A.dylib                 0x00005958 _objc_terminate + 104
6   libstdc++.6.dylib               0x00042df2 __cxxabiv1::__terminate(void (*)()) + 46
7   libstdc++.6.dylib               0x00042e46 std::terminate() + 10
8   libstdc++.6.dylib               0x00042f16 __cxa_throw + 78
9   libobjc.A.dylib                 0x00004838 objc_exception_throw + 64
10  CoreFoundation                  0x000a167c -[NSObject(NSObject) doesNotRecognizeSelector:] + 96
11  CoreFoundation                  0x000491d2 ___forwarding___ + 502
12  CoreFoundation                  0x00048f88 _CF_forwarding_prep_0 + 40
13  Foundation                      0x000146ac _nsnote_callback + 136
14  CoreFoundation                  0x0002670c __CFXNotificationPost_old + 396
15  CoreFoundation                  0x000263ac _CFXNotificationPostNotification + 112
16  Foundation                      0x0000b014 -[NSNotificationCenter postNotification:] + 132
17  [My Application]                0x000a5ad2 -[PortfolioUpdateOperation main] (PortfolioUpdateOperation.m:37)
18  Foundation                      0x0000e9e8 -[__NSOperationInternal start] + 652
19  Foundation                      0x0000e74c -[NSOperation start] + 16
20  Foundation                      0x00023574 ____startOperations_block_invoke_2 + 40
21  libSystem.B.dylib               0x000d597c _dispatch_call_block_and_release + 12
22  libSystem.B.dylib               0x000d675c _dispatch_worker_thread2 + 120
23  libSystem.B.dylib               0x0007a67a _pthread_wqthread + 258
24  libSystem.B.dylib               0x00073190 start_wqthread + 0

I've recently had a crash concerning a selector not being found when a notification was posted using NSNotificationCenter. What can be causing this error?

I've noticed that there was no user code being called after the notification was posted, so that doesn't seem to be a problem on the receiving side of the notification. However, what could cause NSNotificationCenter to crash?

Here's the stack trace of the call:

0   libSystem.B.dylib               0x00078ac8 __kill + 8
1   libSystem.B.dylib               0x00078ab8 kill + 4
2   libSystem.B.dylib               0x00078aaa raise + 10
3   libSystem.B.dylib               0x0008d03a abort + 50
4   libstdc++.6.dylib               0x00044a20 __gnu_cxx::__verbose_terminate_handler() + 376
5   libobjc.A.dylib                 0x00005958 _objc_terminate + 104
6   libstdc++.6.dylib               0x00042df2 __cxxabiv1::__terminate(void (*)()) + 46
7   libstdc++.6.dylib               0x00042e46 std::terminate() + 10
8   libstdc++.6.dylib               0x00042f16 __cxa_throw + 78
9   libobjc.A.dylib                 0x00004838 objc_exception_throw + 64
10  CoreFoundation                  0x000a167c -[NSObject(NSObject) doesNotRecognizeSelector:] + 96
11  CoreFoundation                  0x000491d2 ___forwarding___ + 502
12  CoreFoundation                  0x00048f88 _CF_forwarding_prep_0 + 40
13  Foundation                      0x000146ac _nsnote_callback + 136
14  CoreFoundation                  0x0002670c __CFXNotificationPost_old + 396
15  CoreFoundation                  0x000263ac _CFXNotificationPostNotification + 112
16  Foundation                      0x0000b014 -[NSNotificationCenter postNotification:] + 132
17  [My Application]                0x000a5ad2 -[PortfolioUpdateOperation main] (PortfolioUpdateOperation.m:37)
18  Foundation                      0x0000e9e8 -[__NSOperationInternal start] + 652
19  Foundation                      0x0000e74c -[NSOperation start] + 16
20  Foundation                      0x00023574 ____startOperations_block_invoke_2 + 40
21  libSystem.B.dylib               0x000d597c _dispatch_call_block_and_release + 12
22  libSystem.B.dylib               0x000d675c _dispatch_worker_thread2 + 120
23  libSystem.B.dylib               0x0007a67a _pthread_wqthread + 258
24  libSystem.B.dylib               0x00073190 start_wqthread + 0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

以往的大感动 2024-10-10 10:33:26

NSNotificationCenter 很可能正在尝试通知不再存在的对象实例。

换句话说,对象被释放时没有将其本身作为 NSNotificationCenter 观察者删除。检查代码中是否有对象将自身添加为 NSNotificationCenter 观察者但无法从 NSNotificationCenter 中删除自身的情况。

Most likely NSNotificationCenter is trying to notify an object instance that no longer exists.

In other words, an object was deallocated without removing itself as a NSNotificationCenter observer. Check your code for cases when an object adds itself as a NSNotificationCenter observer but fails to remove itself from NSNotificationCenter.

埋葬我深情 2024-10-10 10:33:26

看起来您添加了一个对象作为观察者,但它不响应您提供的选择器。确保您的通知方法接受一个 NSNotification 类型的参数

Looks like you added an object as an observer that doesn't respond to the selector you provided. Make sure your notification method accepts one argument of type NSNotification

独守阴晴ぅ圆缺 2024-10-10 10:33:26

也许检查 respondsToSelector 然后记录对象的类名等可以进一步帮助您?

Maybe a check to respondsToSelector followed with some logging of the object's class name etc could help you further?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文