是否有一个内置方法可以在应用程序即将关闭时调用?
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据“关闭”的类型,有一些回调会发送到应用程序委托。
当应用程序即将从活动状态转变为非活动状态时发送。对于某些类型的临时中断(例如来电或 SMS 消息)或当用户退出应用程序并开始转换到后台状态时,可能会发生这种情况。
使用此方法可以暂停正在进行的任务、禁用计时器并降低 OpenGL ES 帧速率。游戏应该使用此方法来暂停游戏。
使用此方法可以释放共享资源,保存用户数据,使计时器无效,并存储足够的应用程序状态信息,以便将应用程序恢复到当前状态,以防应用程序稍后终止。
如果您的应用程序支持后台执行,则在用户退出时调用而不是 applicationWillTerminate: 。
当应用程序即将终止时调用。
There's a few callbacks that get sent to the application delegate depending on the type of "close".
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.
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.
Called when the application is about to terminate.
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.