是否有一个内置方法可以在应用程序即将关闭时调用?

发布于 2024-09-30 09:22:50 字数 101 浏览 3 评论 0原文

我有一个 iphone 应用程序,我需要在应用程序即将关闭时捕获一些数据...

是否可以将方法调用与单击 iphone 主页按钮相关联?这样我就可以获得特定类型的最新数据?

I have an iphone app, and I need to capture some data right as the app is about to close...

Is it possible to associate a method call with the clicking of the iphone home button? So that I can get the most recent and current data of a particular type that I can?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

栖竹 2024-10-07 09:22:50

根据“关闭”的类型,有一些回调会发送到应用程序委托。

- (void)applicationWillResignActive:(UIApplication *)application;

当应用程序即将从活动状态转变为非活动状态时发送。对于某些类型的临时中断(例如来电或 SMS 消息)或当用户退出应用程序并开始转换到后台状态时,可能会发生这种情况。
使用此方法可以暂停正在进行的任务、禁用计时器并降低 OpenGL ES 帧速率。游戏应该使用此方法来暂停游戏。

- (void)applicationDidEnterBackground:(UIApplication *)application;

使用此方法可以释放共享资源,保存用户数据,使计时器无效,并存储足够的应用程序状态信息,以便将应用程序恢复到当前状态,以防应用程序稍后终止。
如果您的应用程序支持后台执行,则在用户退出时调用而不是 applicationWillTerminate: 。

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

当应用程序即将终止时调用。

There's a few callbacks that get sent to the application delegate depending on the type of "close".

- (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, called instead of applicationWillTerminate: when the user quits.

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

Called when the application is about to terminate.

看春风乍起 2024-10-07 09:22:50

applicationWillResignActive 委托是在应用程序关闭之前保存数据的好地方,但是当应用程序只是暂时中断或在后台存储一段不确定的时间时,可能会调用该委托。

在 iOS 4.0 及更高版本中,即使应用程序在后台即将被终止,也不会调用 applicationWillTerminate。所以它实际上只对一些添加的 iOS 3.x 支持有用。

The applicationWillResignActive delegate is a good place to save data before an app closes, but may be called when the app is only going to be temporarily interrupted, or stored in the background for an indeterminate period.

Under iOS 4.0 and later, applicationWillTerminate is not called, even if the app is about to be killed while in the background. So it's really only useful for some added iOS 3.x support.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文