"applicationWillTerminate" not called

Hello,

I would like to detect when the app is task killed (i.e. removed from background). I thought "applicationWillTerminate" is called at that time, but not called.

How can I detect if the app is deleted from background.

Thanks for your help in advance.

Self resolved.

I found another method which does not require "applicationWillTerminate".

Thanks anyway.

Accepted Answer

Self resolved.

I found another method which does not require "applicationWillTerminate".

Thanks anyway.

Congrats.

But maybe what you found can be of interest for others ?

That's a good practice on the forum to explain how and issue was solved. Not only announce it was solved (which doesn't really matter for other developers)

OK. I did the followings;

class AppDelegate: NSObject, UIApplicationDelegate {
    
    private var isTaskKilled = true

    func applicationDidEnterBackground(_ application: UIApplication) {
        isTaskKilled = false
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        if isTaskKilled {
            // Do something when task killed.
        }
    }
}
"applicationWillTerminate" not called
 
 
Q