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

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

问题描述

在 iOS 4.0 中未调用 applicationWillTerminate 委托方法当我点击 Home 按钮时,我看到 applicationWillResignActive 和 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{

}

我什至尝试点击减号并删除后台运行的应用程序,但它仍然没有调用任何委托方法.

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: 通常不会在 iOS 4 中经常被调用.如果你必须保存数据,你应该在 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:.

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

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