Mac Catalyst app doesn't terminate when window is closed

Create a simple empty sample project. Enable Mac Catalyst. Build and run on your Mac. Now close the one window and note that the program actually terminates and the debugger session ends. Perfect.


Unfortunately my actual app doesn't terminate when the one and only app window is closed. If I close the window the program keeps running. The window is gone but it doesn't terminate. Clicking on the pause icon in the debugger and looking at the thread stacktraces doesn't show anything of my own code running.


If I pause the app every once in a while and look at the threads, while none seem to show anything really happening, new threads are being created and finshed. But these transient threads rarely show more than a single stack entry with things like "start_wqthread" or "__workq_kernreturn".


I even went so far as commenting out everything possible in the app delegate and scene delegate such that my app didn't run any code except creating an empty window with no root view controller and it still won't terminate when the (empty) window is closed. Of course the app still has a whole bunch of frameworks and pods linked in.


So I'm looking for ideas on what could possibly make an iOS app running under Mac Catalyst fail to terminate when the last window is closed.


I tried to look at the memory graph but Xcode just gives an error (Unable to acquire required taks port). But I get that with any Mac Catalyst app.


I'm stuck and this failure to terminate is causing problems.


Thanks for any ideas.

Post not yet marked as solved Up vote post of RickMaddy Down vote post of RickMaddy
3.3k views

Replies

I believe if you use scenes, it's not appropriate for your app to stop when the last scene is closed. When you build an "empty sample project", is it using scenes? If not, then I could see how Apple translates that into quitting the app when the window closes. Does your app use scenes? It sounded like it did. A multi-windowed mac app wouldn't quit when all the documents are closed. It would stay open to allow you to do things like open a recent file, or select "New" from the File menu.

Yes, when you create a new Single View app and run it with no changes, it is using scenes. That is the default under iOS 13. And closing the only window terminates the app.


Yes, my iPad/Mac Catalyst app uses scenes. But even with only one scene open, it doesn't terminate like a newly created project does.


True macOS apps can be configured to automatically quit when the last window is closed. Then there are apps like Preview that stays open with no windows until the user switches to another app.

I don't know the answer, cuz I haven't messed with Catalyst at all, but in Appkit, there's a method in the NSApplicationDelegate protocol:


-(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)sender;


Is there no way for a catalyst app to interact with raw Appkit API on the Mac target?

Depends - from the docs:


Important

iPad apps running in macOS can only use AppKit APIs marked as available in Mac Catalyst, such as

NSToolbar
and
NSTouchBar
. Mac Catalyst does not support accessing unavailable AppKit APIs.


>on the Mac target?


I think the term in this example is targetEnvironment, or version, but I get your point.


Technically you work with the 'iOS target' that you want to configure for use w/mac catalyst.