App Delegate 的方法 willTerminate 什么时候执行?
When App Delegate's method willTerminate is executed?
目前我正在测试 AppDelegate
方法,当它们通过向每个方法添加 NSLog
来执行时。我不清楚的是方法 applicationWillTerminate
何时执行?我试图将应用程序置于后台,然后终止它,但未执行来自 Terminate 方法的日志。执行的是这样的:
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
几乎从不。它可以在某些罕见的情况下被调用,例如在后台播放音乐并从那里终止。但通常你应该期望它永远不会被调用,因为当你被终止时,你已经被挂起并且你的代码不再是 运行 (并且系统不会唤醒你只是为了告诉你它在后台杀了你)。
applicationWillTerminate 将执行一次是在用户触摸(一次或两次)主页按钮然后将应用程序滑出屏幕时。
就我个人而言,我经常这样做,因为我触摸主页按钮来切换我想要激活的常用应用程序,而不是在我的 9 页图标中找到它们。
目前我正在测试 AppDelegate
方法,当它们通过向每个方法添加 NSLog
来执行时。我不清楚的是方法 applicationWillTerminate
何时执行?我试图将应用程序置于后台,然后终止它,但未执行来自 Terminate 方法的日志。执行的是这样的:
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
几乎从不。它可以在某些罕见的情况下被调用,例如在后台播放音乐并从那里终止。但通常你应该期望它永远不会被调用,因为当你被终止时,你已经被挂起并且你的代码不再是 运行 (并且系统不会唤醒你只是为了告诉你它在后台杀了你)。
applicationWillTerminate 将执行一次是在用户触摸(一次或两次)主页按钮然后将应用程序滑出屏幕时。
就我个人而言,我经常这样做,因为我触摸主页按钮来切换我想要激活的常用应用程序,而不是在我的 9 页图标中找到它们。