1

currently I am testing AppDelegate methods, when they are executed by adding NSLog to every method. What is not clear to me is when method applicationWillTerminate is executed? I've tried to put app in background, then to terminate it, but log from Terminate method is not executed. What is executed is this:

2015-09-01 16:24:01.512 TestQuestions[2351:110179] didFinisLaunching
2015-09-01 16:24:02.530 TestQuestions[2351:110179] didBecomeActive
2015-09-01 16:24:05.864 TestQuestions[2351:110179] willResign
2015-09-01 16:24:06.322 TestQuestions[2351:110179] didEnterBackground
Stefan
  • 1,283
  • 15
  • 33

2 Answers2

4

What is not clear to me is when method applicationWillTerminate is executed

Almost never. It can be called under certain rare circumstances where you are e.g. playing music in the background and are terminated from there. But in general you should expect that it will never be called, because by the time you are terminated, you are already suspended and your code is no longer running (and the system is not going to wake you up just to tell you it's killing you in the background).

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Thank for answer. How that app knows that is terminated from background? – Stefan Sep 01 '15 at 14:28
  • 1
    Did you read what I just said? It doesn't "know" because it has already been suspended. It is just killed, like the scientists in 2001 : A Space Odyssey who are killed by HAL 9000 while they are already in suspended animation. – matt Sep 01 '15 at 14:31
  • Ok. Thanks. This really helped me. – Stefan Sep 01 '15 at 14:32
0

One time that applicationWillTerminate will execute is when a user touches (once or twice) the Home button and then slides the app off the screen.

Personally I do this regularly since I touch the Home button to switch between regularly used apps that I want to make active, rather that finding them in my 9 pages of icons.

KiloOne
  • 312
  • 1
  • 6
  • 20