objective-c - 订阅(或列出)所有应用程序分发的通知

标签 objective-c macos cocoa

我需要 iTunes 和 Spotify 发布的所有已分发通知的列表。我似乎在 SO 或 Google 上找不到这样的东西,所以我想看看我是否可以订阅所有通知并记下哪些通知被触发。我已成功订阅其中一份,但无法订阅全部。

// Works just fine
NSDistributedNotificationCenter *center = [NSDistributedNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(itunesNotification)
               name:@"com.apple.iTunes.playerInfo" object:nil];
[center addObserver:self selector:@selector(spotifyNotification)
               name:@"com.spotify.client.PlaybackStateChanged" object:nil];

// Doesn't work :(
[center addObserver:self selector:@selector(itunesNotification)
               name:@"com.apple.iTunes" object:nil];
[center addObserver:self selector:@selector(itunesNotification)
               name:@"com.apple.iTunes.*" object:nil];
// Same result with com.spotify.client and .*

同样,如果我能有一个所有 iTunes/Spotify 通知的列表,那也可以。我的目的不是最终订阅所有通知,而是看看有什么并选择一些。希望这是有道理的,非常感谢!

最佳答案

我明白了!您可以通过提供 nil 作为名称来观察 Mac 上所有分发的通知。

NSDistributedNotificationCenter *center = [NSDistributedNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(allNotifications:) name:nil object:nil];

关于objective-c - 订阅(或列出)所有应用程序分发的通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27735614/

相关文章:

macos - C++、OS X 的 clang 与 GCC 中的 Lambda 表达式

macos - 以编程方式获取系统安装日期

objective-c - 将 NSValue 转换为 NSData,然后以正确的类型再次转换回来

mysql - 在 Mac 上将数据库导入 MAMP

python - 在 MacOS Sierra 上安装 Pillow

cocoa - Apple 不再接受使用 QuickTime API 的应用程序提交

swift - 当 App 显示 NSAlert 时保持 Cocoa 窗口最小化

iphone - 将一个图像放在另一个图像之上

objective-c - Sprite 套件 Sprite 未被着色

ios - 如何在iOS 6/7中将图像保存到相机胶卷/相册?