iOS life cycle, application termination

I've found that, in iOS 13 (Have tested 13.0 and 13.5), the UIApplicationDelegate:applicationWillTerminate and the UIWindowSceneDelegate:sceneDidDisconnect methods, when the application is dismissed from the app switcher:
  • are called when the app was active upon invoking the switcher

  • are not called when the app was in background upon invoking the switcher

This makes it difficult to reliably do application cleanup that applies when the app terminates or scene is discarded, that does not apply when the app or scene goes to background.

What is the reliable way to do some cleanup when the app (or final scene) is dismissed from the app switcher?

Here is a related question and answer from StackOverflow: https://stackoverflow.com/questions/58573015/in-ios-13-what-events-do-i-get-when-the-user-swipes-my-app-up-in-the-app-switch/58573016#58573016
iOS life cycle, application termination
 
 
Q