6 Replies
      Latest reply on Jan 30, 2020 6:38 PM by pabugeater
      RickMaddy Level 1 Level 1 (0 points)

        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.

        • Re: Mac Catalyst app doesn't terminate when window is closed
          ben_singaccord Level 1 Level 1 (0 points)

          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.

            • Re: Mac Catalyst app doesn't terminate when window is closed
              RickMaddy Level 1 Level 1 (0 points)

              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.