0

我有一个应用程序可以将手机上创建的记录与网络服务器同步。

当应用程序没有互联网连接时,它将所有内容存储在本地(核心数据),然后在互联网再次可用时同步。

现在一个用户提出了一个有效的用户案例场景......假设他在飞机上制作记录(没有网络)......所以所有内容都存储在本地。一切都很好,直到空姐命令他关掉电话。在应用程序中,如果关闭,他会立即关闭。现在数据正在丢失。当应用程序进入后台甚至手机被锁定时,我正在保存状态。但我如何保证这一点?

当用户关闭手机(长按锁定按钮)时,他们仍然需要滑动一个栏,并且设备需要一些时间才能关闭......所以有一些时间我可以将状态保存在......调用哪个委托方法在这段时间?

4

1 回答 1

3

Your app will get applicationWillResignActive, applicationDidEnterBackground, applicationWillTerminate calls, in that order.

http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW3

You can use applicationWillTerminate as a cue to save stuff.

However it is standard good practice to make sure your data is saved periodically as you go along and not just in these situations - what about if your user has entered lots of lots and data and then your app crashes, the data will be lost.

I'm not very familiar with Core Data but surely it must have atomic save ability.

于 2012-06-07T16:45:10.197 回答