How To Detect When App Is Force Closed in Background Swift

EvanOgo picture EvanOgo · Nov 23, 2016 · Viewed 8.3k times · Source

If my app is running in the background, and I force close it, how can I get the app to detect it was force closed in the background? Is there a specific function I can call to detect this?

Answer

Ivan Nesterenko picture Ivan Nesterenko · Nov 23, 2016

You can use

 func applicationWillTerminate(_ application: UIApplication) {

 }

within AppDelegate class to observe when the app will be terminated. Documentation.

Edit: Please, note that as it written in docs

Suspended apps are not notified of termination