-1

I have to execute some code of my app (down/upload data from my server) periodically (once a day) as I asked there.

I read that it is not possible to execute any code from the app when it has been killed by user through UI while it is possible under certain conditions when app has been terminated by system.

I don't really understand what state is reached in such both cases. Non-running ? Suspended ? How to distinguish these cases in following diagram ?

enter image description here

babaaba78
  • 69
  • 1
  • 5
  • This question is already asked: https://stackoverflow.com/questions/7343404/how-to-know-whether-app-is-terminated-by-user-or-ios-after-10min-background possibility to duplicate. – Sumit singh Dec 06 '18 at 16:27
  • It is not exactly the same question. I ask whether these both app terminations put the application in the same state. – babaaba78 Dec 06 '18 at 17:22

1 Answers1

2

If a user closes your application but does not quit it from the app switcher, you will be immediately backgrounded and allowed to execute code for a short and arbitrary period of time until your application is suspended. The system decides when you move to this state and you have no power to keep yourself alive in the background beyond what time iOS grants you.

After this time expires you are no longer allowed to execute code until you're either foregrounded by the user or receive a remote notification in the suspended state. If you receive a push while suspended, you will be allowed to execute code in the background again for a short period of time until you are suspended again.

If a user quits your app from the app switcher you will immediately switch to the not-running state and will no longer be able to execute code unless your app is relaunched. This will also prevent the system from attempting to preserve and restore the app's state on relaunch.

Developers also need to be aware that the operating system may terminate the app at any time from the background if the phone decides to reclaim the resources that keep you suspended.

Dare
  • 2,497
  • 1
  • 12
  • 20
  • As far as I understand, the state of the app is exactly the same when the users kills it from the app switcher and when the system terminate it while it was in background. Is that correct ? – babaaba78 Dec 06 '18 at 17:19
  • 1
    Yes in both cases the app is not running. However, the state restoration framework intentionally discards any state information when the user manually kills an app so that your app doesn’t get stuck in an infinite loop of restoration crashes. In that respect the lifecycle will be different slightly on relaunch depending on whether the app was killed by the system or the user. – Dare Dec 06 '18 at 19:19