title: How to detect when a user terminates an app - Swift
body: <p>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.</p>
  <p><code>func applicationWillTerminate(_ application: UIApplication)</code>: Called when (most) apps are terminated, but not for apps that support background execution.</p>
  <p><code>func sceneDidEnterBackground(_ scene: UIScene)</code>: Called when the scene enters the background, but can't differentiate between the app entering the background versus terminating completely.</p>
  <p><code>func sceneDidDisconnect(_ scene: UIScene)</code>: 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..</p>
  <p><strong>// EDIT:</strong> So I realized the above method (<code>sceneDidDisconnect</code>) 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.</p>
  <p>Is there a function that's called every time a user terminates an app???</p>