我需要 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/