InstallApplicatonEventHandler/NSNotificationCenter 不通知事件 (NS

InstallApplicatonEventHandler/NSNotificationCenter doesnt notify events (NSN)

本文关键字:事件 NS 通知 NSNotificationCenter InstallApplicatonEventHandler      更新时间:2023-10-16

我想在mac os中注册时间更改通知。我尝试了ApplicaitonEventHandler api,它似乎是这种情况的api,但我没有收到任何事件的通知

代码共享于,

https://gist.github.com/anonymous/a0b3e24e02b844bfb11e2b5d02e47d83

我注册了所有可能的事件,但触发任何事件似乎并没有为我创建通知。

我正在使用 .mm 扩展名,因为我希望我的代码公开为 c 样式的 api,并且如果可能的话,我可以与私有目标 c 类互操作(即如果目标 c 对象可以在 c++ 方法中实例化并且合适的目标 c api 可用于此类通知(。

[注意] 使用了下面建议的 NSNotization,它也不会发送任何通知。

如果你只想在时钟更改时收到通知,你可以收听com.apple.MenuBarClock.ClockNotification。

[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(timeChanged:) name:@"com.apple.MenuBarClock.ClockNotification" object:nil suspensionBehavior:NSNotificationSuspensionBehaviorDeliverImmediately];