简体   繁体   English

NSDistributedNotifications不分布在(相同)应用程序的实例之间

[英]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版本),我也会得到如下所示的简单信息:

  1. Splendidly working notifications 'locally' (Like with a NSNotificationCenter) but 出色的“本地”工作通知(例如NSNotificationCenter),但是
  2. No inter-app comms when I start the app up twice (eg from the command line) 当我两次启动应用程序时(例如,从命令行),没有应用程序间通信
  3. No notifications when another apps registers for this (or for nill) 当其他应用程序为此注册(或无效)时没有通知
  4. No debug/info in the distnoted daemon logs either. 分布式守护进程日志中也没有调试/信息。

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 我为此找到了三种解决方法-都不是那么好-它们都涉及

  1. adding a deliverImmediately:YES to the posting, 在发布中添加一个deliverImmediately:YES
  2. a deliverImmediately: with NSNotificationSuspensionBehaviorDeliverImmediately to the observer or deliverImmediately:使用NSNotificationSuspensionBehaviorDeliverImmediately立即deliverImmediately:给观察者或
  3. setting a timer to intentionally interrupt the runLoop every seconds. 设置计时器以故意每秒钟中断一次runLoop。

Obviously - none of this comes cheap. 显然-这些都不便宜。

Dw w

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有苹果应用商店,TutuApp如何公开发行? - How TutuApp is being distributed publicly without Apple's app store? 在同一个应用iPhone中的设备之间共享数据 - Sharing data between device in same app iPhone 如何防止我的 macOS 应用程序同时运行多个实例? - How do I prevent my macOS app from having multiple instances running at the same time? 使用分布式对象的过程之间的通信 - Communication between process using Distributed Object 主应用目标和应用的扩展版本号应该相同? - Main App target and app's extension build number should be same? 在启动完成之前,企业分布式iOS应用程序崩溃不一致 - Enterprise Distributed iOS App Crashes Inconsistently Before Launch Finishes 使用iOS分布式应用时,Google Cloud Messaging会显示“notRegistered” - Google Cloud Messaging shows “notRegistered” when using iOS distributed app 临时分布式应用程序未在 iOS 14.0 及更高版本上下载 - Ad-hoc distributed app not downloading on iOS 14.0 and above Objective-C #ifdef DEBUG 在应用分发时为真? - Objective-C #ifdef DEBUG is TRUE when the app is distributed? 同一结构 SwiftUI 的单独实例 - Separate Instances of Same Struct SwiftUI
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM