存储applicationWillTerminate之外的值 [英] Store a value beyond applicationWillTerminate

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

问题描述

我在Apple的iOS开发中心搜索过但找不到任何正确的内容。这是我的问题:

I have searched in Apple's iOS dev center but couldn't find anything quite right. Here's my problem:

我有一个使用CoreData和几个实体的应用程序。数据通过服务器动态更新。现在每次应用程序变为活动状态时都会调用 checkForUpdates ,但仅在上次更新后经过一定时间后执行。

I have an app that uses CoreData with several entities. The data is dynamically updated via a server. Now checkForUpdates is called every time the app becomes active, but is only executed when a certain amount of time passed since the last update.

checkForUpdates 最终被执行时,它会更新所有内容,如果服务器上的版本是最新版本,则检查每个对象。更新已完成。

When checkForUpdates is finally executed it updates all the content, checking for each object if the version on the server is a more recent one according to the last time an update was done.

我的更新程序类中有一个局部变量,类型为 NSDate 保存上次成功完成更新的时间。我需要能够以某种方式存储此值以及应用程序终止之外的某个地方。

I have a local variable in my Updater class of type NSDate that holds the last time an update was successfully done. I need to be able to store this value somehow and somewhere beyond termination of the application.

我想知道什么是内存方面最具成本效益的方式以及在表现方面。看看iOS开发中心,我首先考虑了应用程序首选项,但由于它只是一个值,我认为会有更简单的方法。很抱歉,如果这很容易,但我是Objective-c和iOS编程的新手。

I was wondering what would be the most cost-effective way memory-wise and also in terms of performance. Looking at the iOS dev center I first thought about application preferences, but since it is only a single value I thought there would be an easier way. Sorry if this is really easy but I'm new to objective-c and iOS programming.

任何帮助都将不胜感激!如果需要更多信息,请随时在下面发表评论。

Any help would be appreciated! If more information is needed feel free to comment below.

编辑:仅使用<创建新的权利是否是一个好主意code> NSDate 属性并在我的数据库中保留 lastUpdateTime 变量?

edit: Would it be a good idea to simply create a new entitiy with an NSDate attribute and to simply keep the lastUpdateTime variable in my database?

最好的问候,
Octoshape

Best regards, Octoshape

推荐答案

听起来你想要 NSUserDefaults 存储。它像字典一样使用,但仍然存在:

Sounds like you want the NSUserDefaults storage. It's used like a dictionary, but persists:

[[NSUserDefaults standardUserDefaults] setObject:myDate forKey:@"LastUpdateTime"];

这篇关于存储applicationWillTerminate之外的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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