ApplicationWillTerminate在iOS 4.0中 [英] ApplicationWillTerminate in iOS 4.0

查看:119
本文介绍了ApplicationWillTerminate在iOS 4.0中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 4.0中没有调用applicationWillTerminate委托方法
当我点击Home按钮时,我看到appWillResignActive和applicationDidEnterBackground委托方法被调用。

The applicationWillTerminate delegate method is not getting called in iOS 4.0 When I hit the Home button I am seeing the applicationWillResignActive and applicationDidEnterBackground delegate methods getting called.

 - (void)applicationWillResignActive:(UIApplication *)application
{
  NSLog(@"Application Did Resign Active");
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
  NSLog(@"Application Did Enter Background");
}

当我双击主页按钮并再次启动应用程序时,我发现调用applicationWillEnterForeground和applicationDidBecomeActive委托方法。

And when I double Tap the Home button and again launch the Application the i find the applicationWillEnterForeground and applicationDidBecomeActive delegate methods are getting called.

 - (void)applicationWillEnterForeground:(UIApplication *)application
{
  NSLog(@"Application Will Enter Foreground");
}



- (void)applicationDidBecomeActive:(UIApplication *)application
{
  NSLog(@"Application Did Become Active");
}

但我想知道何时调用applicationWillTerminate委托方法,我在哪里做一些数据库/文件备份例程。

But I want to know when the applicationWillTerminate delegate method will be called , where I do some DB/file backup routines.

- (void)applicationWillTerminate:(UIApplication *)application{

}

我甚至试图点击减号并删除在后台运行的App,但是仍然没有调用任何委托方法。

I even tried to hit the minus sign and deleted the App running in the Background , but still it did not call any delegate method.

任何想法???

推荐答案

从iPhone应用程序编程指南:

From the iPhone Application Programming Guide:


即使您使用iPhone SDK 4及更高版本开发应用程序,您仍必须为您的申请准备终止。如果内存受限制,系统可能会从内存中删除应用程序以腾出更多空间。如果您的应用程序当前处于暂停状态,系统会在不事先通知的情但是,如果您的应用程序当前正在后台运行,则系统会调用应用程序委托的 applicationWillTerminate:方法。您的应用程序无法通过此方法请求额外的后台执行时间。

Even if you develop your application using iPhone SDK 4 and later, you must still be prepared for your application to be terminated. If memory becomes constrained, the system might remove applications from memory in order to make more room. If your application is currently suspended, the system removes your application from memory without any notice. However, if your application is currently running in the background, the system does call the applicationWillTerminate: method of the application delegate. Your application cannot request additional background execution time from this method.

是的, applicationWillTerminate:。如果必须保存数据,则应在 applicationWillTerminate: applicationDidEnterBackground中执行此操作:

So yes, applicationWillTerminate: will generally not be called very often in iOS 4. If you have to save data, you should do so in both applicationWillTerminate: and applicationDidEnterBackground:.

这篇关于ApplicationWillTerminate在iOS 4.0中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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