Search code examples
cocoaosx-lionnsnotificationcenternsnotification

NSNotificationCenter Observer stops receiving events when app is out of focus on Lion


I have an app that subscribes to a specific kind of notifications from the default NSNotificationCenter.

On OSX Lion, it works fine, except that when the app loses the focus (another app becomes active), it stops receiving the events. When the app gains the focus, it starts receiving events again. The app did not have this behavior on previous versions of OSX, it always received notifications, even when it was out of focus.

What can I do to change this behavior?

Thanks! Nathan


Solution

  • It looks like the default behavior when adding an observer to a NSDistributedNotificationsCenter has changed to NSNotificationSuspensionBehaviorCoalesce, that does not deliver notifications when the app is inactive.

    Described here: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDistributedNotificationCenter_Class/Reference/Reference.html#//apple_ref/doc/uid/20000396-5567