在 10.7.2 上,我无法让标准 NSDistributedNotifications 开箱即用。
即使回到只是(https://github.com/dirkx/Example-NSDistribtuedNotification-Failing上的完整 XCode 版本)到如下简单的东西我得到:
- 出色的“本地”通知(就像 NSNotificationCenter 一样)但是
- 当我启动应用程序两次时没有应用程序间通信(例如从命令行)
- 当其他应用程序注册此(或为零)时没有通知
- distnoted 守护程序日志中也没有调试/信息。
我错过了什么?
NSString * kSayNotification = @"org.webweaving.sayExample";
// Send a Distributed Notification on button press.
//
-(IBAction)buttonChange:(NSButton *)sender {
NSString * str = (sender.state == NSOnState) ? @"Yes" : @"No";
[[NSDistributedNotificationCenter defaultCenter]
postNotificationName:kSayNotification
object:str
];
}
// Update a label on receiving a Notification.
//
-(void)notif:(NSNotification *)nf {
.. snipped time string ...
// Textfield with the time of arrival and the value passed in the notification.
//
textField.stringValue = [NSString stringWithFormat:@"%@: %@",
dStr, (NSString *)nf.object
];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Register for the notifications.
//
[[NSDistributedNotificationCenter defaultCenter]
addObserver:self
selector:@selector(notif:)
name:kSayNotification
object:nil];
}
顺便说一句 - 通知观察者(https://github.com/melo/notification-watcher)不显示通知 - 但通知是在应用程序内处理的。