0

I create a new empty project in Unity and build it on iOS platform and run it on Mac Catalyst. However, I want to figure out the difference between close and minimize. With the help of log, they both called applicationWillResignActive and applicationDidEnterBackground. But there are no backgroundTasks to do, so why does clicking the close button call applicationWillTerminate after applicationDidEnterBackground while clicking the minimize button doesn't?

And I ask this question because if there are backgroundTasks to do, then clicking close button doesn't really quit the app, it will do backgroundTasks. So I want when clicking close button, I don't want to do backgroundTasks, just call applicationWillTerminate and quit it. But How do I do that? It confuses me very long time...

Any suggestions will be really appreciate!!

  • Thank you for your reply! Sorry for my poor English.. – luuuuyang Oct 13 '21 at 06:29
  • Close and minimize both enter background and do background tasks, is it right? If it's right, I don't want my app do background tasks after clicking close because background task takes a few seconds to finish. The application needs to wait to quit until the background task is finished. I just want to quit my app immediately after clicking close and don't need to do background tasks, but I don't know how? Anyway, thanks!! – luuuuyang Oct 13 '21 at 07:36

1 Answers1

0

You said:

Close and minimize both enter background and do background tasks, is it right?

Yes, the beginBackgroundTask tasks will continue, regardless of whether the user minimized the app or closed the window. It will even do this if the user explicitly quits the app. Only crash or force-quitting will not allow background tasks to proceed.

I don't want my app do background tasks after clicking close because background task takes a few seconds to finish.

The problem is that you do not know if it has been minimized or closed. The macOS willMiniaturizeNotification notification is not available to Catalyst apps.

The application needs to wait to quit until the background task is finished. I just want to quit my app immediately after clicking close and don't need to do background tasks, but I don't know how?

This simply may not be possible in Catalyst apps. Given that this is completely transparent to the end user and only takes a few seconds, you may have to decide whether to live with this constraint. If not, you may be forced to consider AppKit rewrite.


The above was a Catalyst question, but for AppKit developers, to get the app to exit when you close the window, implement applicationShouldTerminateAfterLastWindowClosed. Not relevant here, but it is how to control the behavior of the close button in AppKit.

Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • Thank you for your reply! A compromise solution can be adopted without background tasks, so that applicationWillTerminate will be called and quit the app. And yes, rewriting AppKit is also a very good solution, but there are a lot work to do. Anyway, thank you very much!! – luuuuyang Oct 14 '21 at 02:41