0

I'm currently building an app that supports background modes. To name a few, I've registered for background delivery for HealthKit and I'm also montoring for location background events such as didEnterRegion. As I know, if these are called, iOS will temporarily re-launch the app in the background. However, once this is finished, will applicationWillTerminate be called from the background? If not, is there a way to listen for the app to terminate?

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
LFHS
  • 295
  • 1
  • 2
  • 15
  • It says that the app would be terminated after a finite period of time, but it says nothing about whether methods like `applicationWillTerminate` are called – LFHS Dec 10 '17 at 15:19
  • The documentation for `applicationWillTerminate` says, "Called only when the app is running. This method is not called if the app is suspended." It goes on to say "For apps that support background execution, this method is generally not called when the user quits the app because the app simply moves to the background in that case. However, this method may be called in situations where the app is running in the background (not suspended) and the system needs to terminate it for some reason." – Rob Dec 10 '17 at 17:13

3 Answers3

1

No it will not. applicationWillterminate is only called in apps that support background modes when the system needs to terminate it for some reason (memory, normally) if it's not suspended. If it's suspended, the system doesn't send any kind of notification to the app.

You can see more in-depth documentation about the App Life Cycle here: The App Life Cycle Documentation

barbarity
  • 2,420
  • 1
  • 21
  • 29
0

Apps can be suspended at any time, and once they are suspended they can be terminated without further warning. Thus you can't rely on getting an applicationWillTerminate. I believe you will get such a message if your app is actively running (foreground or background) at the time it's terminated, but I'm not certain of that. I am certain that you can't depend getting a terminate message.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
0

Not always!

There are many many reason that cause your app to stop. For example: when system will kill process of your app unexpectedly or for apps that support background execution applicationWillTerminate() will not get called. You do not know when your app fall into this case so you CANNOT rely on this method.

Base on this Apple's document:

For applications that support background execution, this method is generally not called when the user quits the application because the application simply moves to the background in that case. However, this method may be called in situations where the application is running in the background (not suspended) and the system needs to terminate it for some reason

For more information: There is already a S.O question discuss about when this method is called and when not.

nhoxbypass
  • 9,695
  • 11
  • 48
  • 71