如何知道一个应用程序何时在跳板中关闭

时间:2012-01-30 12:25:32

标签: iphone objective-c ipad

我想捕获一个应用程序从跳板关闭以进行一次注销。但是applicationWillTerminate方法不起作用。

有人关注它吗?

由于

3 个答案:

答案 0 :(得分:3)

我相信,你应该按照以下方法进行一次。

- (void)applicationWillResignActive:(UIApplication *)application
{
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
     */
}

您放在applicationWillTerminate中的代码,将其置于上述方法中。
尝试将您的代码放入其中一种方法&检查你的逻辑是否有效。

修改

你的问题指明,你想要检测应用程序强制退出事件 - 这是不可能的。 (抱歉,但不在我手中)

我们通过双击从最小化状态删除应用程序的方式 - 实际上意味着,我们强制退出那些应用程序&这不会触发我们的任何应用程序方法,因为我们的应用程序将被杀死。

答案 1 :(得分:1)

当你说关闭时你的意思是:当一个应用程序从最近使用的栏中关闭时(双击主页按钮)。

您无法检测用户何时关闭您的应用,因为操作系统只会杀死您的应用。这个没有关闭,并且正在调用close方法。

答案 2 :(得分:0)

按主页按钮时,应用程序不会退出/退出。它只是进入背景。因此不会调用applicationWillTerminate。

按两次主页按钮以验证应用程序是否关闭。

还要考虑Spark的答案