10

If app completed ~10 min in background, it will be in suspended mode. App can be killed by below two ways:

  1. iOS can kill the app : In this scenario "applicationWillTerminate" will call.

  2. User can kill apps explicitly using the multitasking UI.(by Double-clicking Home Button and pressing - (red)button)

In second scenario how can we get that app killed by user?

I check below question but no fruitful result: App killed by user

Community
  • 1
  • 1
Vardhan
  • 965
  • 2
  • 11
  • 21
  • 3
    set a NSUserDefaults flag when your background task is done. If the flag is not present at next launch your app has been killed before it reached the end of the background task. – Matthias Bauch Mar 20 '13 at 14:15

1 Answers1

22

If your app is in suspended state then applicationWillTerminate will never get called regardless who killed the app iOS or user.

Your applicationWillTerminate will only call when your app is in background and it gets killed (either by iOS or user) the term background means that it is running in background not in suspended state.

Just read this reference

applicationWillTerminate:—Lets you know that your app is being terminated. This method is not called if your app is suspended.

Here is the table of various states enter image description here

Background - The app is in the background and executing code. Most apps enter this state briefly on their way to being suspended. However, an app that requests extra execution time may remain in this state for a period of time. In addition, an app being launched directly into the background enters this state instead of the inactive state. For information about how to execute code while in the background, see Background Execution.

Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184
  • The reference link is not working now. – Display Name Apr 27 '15 at 06:05
  • Just edited — fixed the link. – Display Name Apr 27 '15 at 06:08
  • I have a problem where my app loses a login token when the app is left in the background, and I try to open it after a long while. The token is saved properly only when the user kills the app, so I deduce there is come trick on applicationWillTerminate, since there IS a difference depending on who kills the app. I read the documentation, but still don't have it clear. Any ideas? What delegate method would you recommend? Thanks. – Josh Mar 20 '17 at 10:43