wigging
wigging

Reputation: 9180

Mac app disappears when window is closed then another app is selected

I created a new macOS project in Xcode 11.4 where the language is Swift and user interface is SwiftUI. Without making any changes to the code in the project, the app will disappear from the dock by performing the following steps:

  1. launch the Mac app by running the Xcode project
  2. close the main window of the Mac app
  3. select another running app such as Safari
  4. the original Mac app disappears from the dock with no way to access it

This behavior does not happen if the window of the Mac app is open. I can select other running apps then go back to the original Mac app with no problems.

Upvotes: 2

Views: 1469

Answers (1)

Ken Thomases
Ken Thomases

Reputation: 90571

This behavior is known as Automatic Termination. I find it a misfeature, but Apple considers it a feature.

Your app may not have actually quit. It may just appear to have quit. "Launching" it again will just make it reappear in the Dock. It's also possible that some apps which look like they're still running have actually been terminated by the system. In theory, if you try to switch to them, they will be launched and told to restore their previous state to maintain the illusion that they were running all along. In practice, apps (even Apple's) rarely properly restore things to exactly how they were.

The process list in Activity Monitor is a true reflection for what is and is not actually running. Look there to determine if your app has really been terminated.

A developer is supposed to have to opt-in to Automatic Termination because it requires explicit coding of state restoration. However, Xcode's app project/target templates have it enabled by default. You can remove the NSSupportsAutomaticTermination key from your Info.plist to disable it.

Likewise, you'll presumably want to disable Sudden Termination, too, if you're not prepared to support it. You would remove the NSSupportsSuddenTermination key.

Upvotes: 6

Related Questions