如何检索所有NSNotificationCenter观察员? [英] How to retrieve all NSNotificationCenter observers?

查看:96
本文介绍了如何检索所有NSNotificationCenter观察员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检索给定通知名称的观察者(对象和选择器)列表。我知道没有官方的API。我也知道我可以子类化NSNotificationCenter 来完成此操作。然而有时候这不是一个可行的选择,因为NSNotificationCenter的用法是遍布代码甚至二进制框架。

I'd like to retrieve a list of observers (objects and selectors) for a given notification name. I know there's no official API for that. I also know I could subclass NSNotificationCenter to accomplish this. Sometimes however this is not a viable option because NSNotificationCenter usage is spread all over the code or even binary frameworks.

所以我正在寻找一个非官方/这个。 (

So I'm looking for an unofficial/private way to do this. (Since it's about debugging only, that's fine.)

推荐答案

最后,苹果添加了一种打印所有通知中心观察者的方法: / p>

Finally, Apple added a way to print all notification center observers:

po [NSNotificationCenter defaultCenter]

它用Name,Object,Observer和Options打印逗号分隔的列表:

It prints a comma separated list with Name, Object, Observer, and Options:

<NSNotificationCenter:0x7f997b307500>
Name, Object, Observer, Options
WebPreferencesRemovedNotification, 0x11165b680, 0x116c87ff8, 1400
UIApplicationWillEnterForegroundNotification, 0x11165b680, 0x7f997a838000, 1400
...

这篇关于如何检索所有NSNotificationCenter观察员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆