[英]NSDistributedNotifications not distributed between instances of (same) app(s)
On 10.7.2 I have trouble getting standard NSDistributedNotifications to work out of the box. 在10.7.2上,我很难使标准的NSDistributedNotifications开箱即用。
Even when brought back to just (Full XCode version at https://github.com/dirkx/Example-NSDistribtuedNotification-Failing ) to something as simple as below I get: 即使回到刚才的简单代码( https://github.com/dirkx/Example-NSDistribtuedNotification-Failing的完整XCode版本),我也会得到如下所示的简单信息:
What am I missing ? 我想念什么?
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];
}
As an aside - notification watcher (https://github.com/melo/notification-watcher) does not show the Notifiactions - but the notifications are processed within the app. 顺便说一句-通知监视程序(https://github.com/melo/notification-watcher)不显示通知-但通知是在应用程序中处理的。
Turns out that when there are no other reasons for CFRunLoop
to return - the messages are queued indefinitely. 事实证明,如果没有其他原因让
CFRunLoop
返回,则消息将无限期排队。 This seems by design. 这似乎是设计使然。
I found three work arounds for this - none of which is that nice - they both involve 我为此找到了三种解决方法-都不是那么好-它们都涉及
deliverImmediately:YES
to the posting, deliverImmediately:YES
, deliverImmediately:
with NSNotificationSuspensionBehaviorDeliverImmediately
to the observer or deliverImmediately:
使用NSNotificationSuspensionBehaviorDeliverImmediately
立即deliverImmediately:
给观察者或 Obviously - none of this comes cheap. 显然-这些都不便宜。
Dw w
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.