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
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).
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.
来源:https://stackoverflow.com/questions/32334132/when-app-delegates-method-willterminate-is-executed