Omer
Omer

Reputation: 5600

How to keep an app from quitting after closing its window on Mac Catalyst?

I started a sample iOS app in order to explore SwiftUI; at some point I thought enabling Mac support would be a fun thing try, and surprisingly, I have good result with little to no additional code.

Testing the app on the Mac, I notice the app quits once I close its window, which is not the way most apps work.

Trying to use applicationShouldHandleReopen is not an option since NSApplicationDelegate is not possible for Catalyst, I was not able to find a counterpart either in UIApplicationDelegate or UISceneDelegate, and I was not able to find anything on this topic on Apple's documentation.

What's the proper way to implement the traditional Mac app behavior(†) on a Catalyst app?

(†) Traditional mac app behavior: When the app window is closed, the app icon remains in the doc and if you click it the apps window reappears again

Upvotes: 2

Views: 1791

Answers (1)

Zehua Chen
Zehua Chen

Reputation: 69

Original answer

To summarize, do one of the followings

  • Using project file
    1. Go to your project file, click on your target
    2. Go to "General" and then go to "Deployment Info"
    3. Go to "Status Bar Style" and then enable "Supports multiple windows"
  • Using Info.plist
    1. Expand "Information Property List"
    2. Expand "Application Scene Manifest"
    3. Set "Enable Multiple Windows" to "YES"

Another answer in the same question recommends setting NSSupportsAutomaticTermination to NO. This also works, but I am not sure if messing with NSSupportsAutomaticTermination brings you "surprises".

Upvotes: 2

Related Questions