iPhone应用程序终止时调用哪个函数? [英] Which function is called when iPhone app is terminated?

查看:102
本文介绍了iPhone应用程序终止时调用哪个函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Xcode版本4.2.1和iOS 5.0中的项目。我想知道当你完全终止一个应用程序时将调用哪个函数,这意味着甚至用户强制在后台运行的应用程序从主屏幕终止的时间。我假设

I'm working on a project in Xcode version 4.2.1 and in iOS 5.0. I'm wondering which function will be called when you completely terminate an application, which means even the time when an users force the app running on background to be terminated from home screen. I was assuming that

(void)applicationWillTerminate:(UIApplication *)application

,但事实证明即使在后台终止应用程序后也没有调用它。
我基本上想要做的是调用我在应用程序完全终止之前创建的方法,因此需要知道在应用程序结束时调用哪个函数。

would be called, but it turned out it was not called even after terminating the app on background. What I basically want to do is to call a method that I created just before the app is completely terminated, so need to know which function is called at the end of the app.

谢谢。

推荐答案

applicationWillTerminate 方法只会在应用程序在终止时未处于挂起状态

"applicationWillTerminate" method will be called only when application is not in suspended state while being terminated.

要理解这一点,考虑到当前您的应用程序处于前台活动状态,请执行以下两个操作案例:

To understand this, considering currently your application is in foreground active state, go through following two cases:

案例1 当您单击主页按钮时,应用会通过调用方法直接进入暂停状态 - (1)applicationWillResignActive然后(2)applicationDidEnterBackground。

Case 1: When you single tap Home button, app directly goes to suspended state by calling methods - (1) applicationWillResignActive and then (2) applicationDidEnterBackground.

现在,当您尝试退出/终止应用时,双击主页按钮,然后向上滑动当前应用屏幕从最近的应用程序屏幕,应用程序处于暂停状态。因此, applicationWillTerminate 方法将不会被调用。

Now when you try to quit/terminate app, by double tapping home button and then swiping up the current app screen from recent app screens, app is in suspended state. So, "applicationWillTerminate" method will not be called.

案例2:当您双击主页按钮时,应用会通过调用方法进入非活动状态 - (1)applicationWillResignActive。

Case 2: When you double tap Home button, app goes to inactive state by calling method - (1) applicationWillResignActive.

现在当您尝试退出/时终止应用程序,通过从最近的应用程序屏幕向上滑动当前应用程序屏幕,应用程序在终止时处于非活动状态(未处于挂起状态)。因此, applicationWillTerminate 方法将被调用。

Now when you try to quit/terminate app, by swiping up the current app screen from recent app screens, app is in inactive state (not in suspended state) while being terminated. So, "applicationWillTerminate" method will be called.

看看Apple说的话:

Look what Apple say:

有关此外观的更多信息 - Apple关于applicationWillTerminate(_ :)的官方文档

For more info on this look - Apple's Official Documentation on applicationWillTerminate(_:)

这篇关于iPhone应用程序终止时调用哪个函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆