Not sure why this is so challenging for me, but how can I detect when the user terminates the app? Because from what I'm seeing, Apple provides a lot of functions that might or might not be called when an app closes.
func applicationWillTerminate(_ application: UIApplication)
: Called when (most) apps are terminated, but not for apps that support background execution.
func sceneDidEnterBackground(_ scene: UIScene)
: Called when the scene enters the background, but can't differentiate between the app entering the background versus terminating completely.
func sceneDidDisconnect(_ scene: UIScene)
: I confirmed this is called if the user directly terminates the app, but if the app is put in the background and then terminated, it isn't called..
// EDIT: So I realized the above method (sceneDidDisconnect
) is indeed the function I was looking for. I previously thought it wasn't being called in the latter case described above, but in actuality, it was. See the (soon to be) accepted answer as well.
Is there a function that's called every time a user terminates an app???