在10.7.2上,我无法使标准的NSDistributedNotifications开箱即用。
即使被带回到(https://github.com/dirkx/Example-NSDistribtuedNotification-Failing处的完整XCode版本),也可以回到下面这么简单的事情,我得到:
我错过了什么?
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)不显示Notifiactions - 但在应用程序中处理的通知。
答案 0 :(得分:0)
事实证明,当CFRunLoop
没有其他原因返回时 - 消息将无限期排队。这似乎是设计的。
我找到了三个解决方案 - 没有一个好 - 他们都涉及
deliverImmediately:YES
deliverImmediately:
NSNotificationSuspensionBehaviorDeliverImmediately
与观察员或了Dw