Friday, October 4, 2019 [Tweets] [Favorites]

NSDistributedNotificationCenter No Longer Supports nil Names

merlinme (via Jeff Johnson):

I’m not sure if this is a bug or an API change, but we have an app which relies on distributed notifications which didn’t work on Catalina. After debugging I think the problem is that specifying a name: nil in addObserver fails silently.

[…]

Apple have now replied to my Feedback submission to confirm that the API has changed. Specifying a nil name in addObserver is now a privileged operation, so for practical purposes all applications currently using a nil name will stop receiving notifications when they move to Catalina, and will need to be updated to use a specified name.

Another breaking change to an API that’s been around since Mac OS X 10.10, without updating the documentation or mentioning the change in a release note:

notificationName The name of the notification for which to register the observer; that is, only notifications with this name are delivered to the observer. When nil, the notification center doesn’t use a notification’s name to decide whether to deliver it to the observer.

I guess maybe there are privacy reasons to prevent an app from seeing notifications from other apps or the system. However:

5 Comments

"It does make things more difficult for legitimate apps that are trying to improve the user experience by monitoring and responding to system changes."

You can't do anything useful without knowing the name of the notification you receive anyway. The major drawback is that know it make it harder to discover them.

That said, if an app running as `root` user can still get them, it would still be possible for devs to discover the notifications and update their apps accordingly.

@Jean-Daniel Yes, that’s what I mean: harder to discover them. Do we know that nil works when running as root?

It's important to note that the primary use of nil for the notification name parameter is not for "discovery". The primary use is for observing multiple notifications from the same sender. This can occur even when the sender and receiver are both your own processes. The API is almost exactly the same as NSNotificationCenter, where you might also use nil to observe multiple notifications from the same sender. This is why the undocumented NSDistributedNotificationCenter change is so bad. If it's for "security", it's merely security theater and breaks legitimate uses of the API.

@Jeff Right, there are two issues here: (1) discovery, no easy workaround, (2) observing multiple of your own notifications, breaks perfectly good code, but easy to work around.

I should have tested before I commented. The Apple Developer forums post didn't have any code, and It turns out that the situation is more complex than "merlinme" suggests:
https://twitter.com/lapcatsoftware/status/1180569607901503490

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment