2

I've implemented a macOS app + extension. The extension might send notifications to the app via DistributedNotificationCenter.default() and postNotificationName(_ name: ...).

The questions is regarding to the app life cycle on macOS - what happens if the user minimized the app, and the extension (which is running) sends a notification with the 'deliverImmediately' flag. Will the app be able to handle it, even while minimized? If no, any other way to achieve this behavior?

P.S - I didn't find anything at the documentation, and when trying to check what happens, sometimes the app got the notification, and sometime it didn't..so asking to check what is the expected behavior.

Witterquick
  • 6,048
  • 3
  • 26
  • 50

1 Answers1

1

The app isn't paused while minimized. Being minimized is a state of NSWindow not NSApplication. The app's run loop still executes, perhaps less frequently, and of course, the window won't be receiving any keyboard or mouse events while minimized, but the app will still be able to process notifications, AppleEvents, network or file I/O, etc... You may need to "un"minimize if the notification involves user interaction in the minimized window with NSWindow.deminiaturize(_ sender: Any?).

If the app is hidden it also still runs, and you'll want to activate it with NSApplication.activate(_ sender: Any?) to do any UI.

Chip Jarred
  • 2,600
  • 7
  • 12