0

I have two Swift macOS apps with running from XCode which are simple listener-notifier programs based on DistributedNotificationCenter. It all seems straightforward, but it is not always working. And it seems pretty random for me. Is there any way to debug this feature? Why sometimes messages is not received or are there maybe some leak of the listener ports? Do you know maybe any tool? I tried to use console logs but I haven't found anything interesting there. Thanks!

Ps. I've noticed that notification is sent when I went machine to Sleep and the Login again. Strange

1 Answer 1

2

Distributed notifications are managed by notifyd on macOS. Use notifyutil to aid debugging:

notifyutil is a command-line utility for interacting with the notify(3) notification system and the notifyd(8) server. It may be used to post notifications, detect and report notifications, and to examine and set the state values associated with notification keys.

Notifications can be delayed or coalesced. The sender can use the options deliver immediately and post to all sessions to ensure delivery:

NSNotificationDeliverImmediately When set, the notification is delivered immediately to all observers, regardless of their suspension behavior or suspension state. When not set, allows the normal suspension behavior of notification observers to take place.

NSNotificationPostToAllSessions When set, the notification is posted to all sessions. When not set, the notification is sent only to applications within the same login session as the posting task.

1
  • 1
    Thanks! options: DistributedNotificationCenter.Options.deliverImmediately solved my issue
    – Przemekeke
    Commented Feb 2 at 12:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .