程序转到后台与applicationWillTerminate不响应

最近对数据进行归档处理,却发现按home键之后,applicationWillTerminate并不响应,

查了一下,发现iOS 4.0之后,按home键已经是处理applicationDidEnterBackground了。

相关文档如下:

Moving to the Background

When the user presses the Home button or the system launches another app, the foreground app transitions
to the inactive state and then to the background state. These transitions result in calls to the app delegate’s
applicationWillResignActive: and applicationDidEnterBackground: methods, as shown in
Figure 3-5. After returning from the applicationDidEnterBackground: method, most apps move to the
suspended state shortly afterward. Apps that request specific background tasks (such as playing music) or
that request a little extra execution time from the system may continue to run for a while longer.

Your app delegate’s applicationDidEnterBackground: method has approximately 5 seconds to finish
any tasks and return. In practice, this method should return as quickly as possible. If the method does not
return before time runs out, your app is killed and purged from memory. If you still need more time to perform
tasks, call the beginBackgroundTaskWithExpirationHandler: method to request background execution
time and then start any long-running tasks in a secondary thread. Regardless of whether you start any

background tasks, the applicationDidEnterBackground: method must still exit within 5 seconds.


程序处理applicationDidEnterBackground之后,系统会让程序有5秒钟的时间来保留数据,对于一般的数据存储,5秒足够了。

你可能感兴趣的:(程序转到后台与applicationWillTerminate不响应)