Intercept Application Quit in Mac Catalyst

Is there a way to determine when the user is about to quit the application while using Mac Catalyst? I'd like to alert the user when they have unsaved changes before they quit, but cannot seem to find how to do that using Mac Catalyst.

It is not possible to cancel Catalyst app termination from your code, but users might implicitly cancel termination and return your app to the foreground+active state by "relaunching" it while it is still finishing background tasks as part of an ongoing termination. For more on this, see Taking iPad Apps for Mac to the Next Level.

Instead of alerting the user to unsaved changes when termination is initiated, ensure that your app automatically saves changes at regular intervals. Additionally, also save any pending changes as soon as the document's scene transitions to the background state.

And in order to be sure your app is allowed to finish saving while in the background state, begin a background task each time you start saving, and end it each time you finish saving.

Note that UIDocument will take care of this for you, if you are using it.

Intercept Application Quit in Mac Catalyst
 
 
Q