与 RestKit 同步
我即将编写一个简单的 iPhone 应用程序,它使用 Core Data 来存储通过 RESTful Web 服务获取的远程数据的本地副本。数据经常更改(添加新记录)。我遇到了 RestKit,我想知道它是否可以满足我的需要。我需要的是在开始时加载所有记录,然后定期下载自上次检查以来添加的记录。显然,即使简单地使用 NSURLConnection 也能实现这一点,这并不神秘,但我希望 RestKit(可能与适当的 Web 服务结合)能够做到这一点,而无需我编写所有同步逻辑。对我来说,关键是只从服务器获取新的/更改的数据。
I'm about to write a simple iPhone app that uses Core Data to store local copy of remote data that is fetched via RESTful web service. The data changes (new records being added) quite often. I came across RestKit and I'm wondering if it can do what I need. And what I need is to load all records in the beginning and then periodically download ONLY records that were added since previous check. Obviously there is no mystery about how that can be accomplished even by simply using NSURLConnection, but I hoped RestKit (probably in combination with a proper web service) would do that without me having to write all the synchronization logic. Again the key for me is that only new/changed data is fetched from the server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我同意 - RestKit 可以做到这一点,我们最近在最近的项目中使用它做了类似的事情。我们使用上次修改日期请求标头来指示上次成功“同步”时间,服务器可以使用该时间仅返回自该日期以来修改的记录。 http 304“未修改”状态代码用于在适当时指示没有更改。
RestKit 还包括一个播种工具,因此您可以预先了解初始数据集 - 您可以轻松地将其播种为初始数据库,并获取更新,即使是在第一次使用应用程序时也是如此。
我发现一些关于 RestKit & 有用的信息CoreData 映射 - https://github.com/RestKit/RestKit/ blob/master/Docs/Object%20Mapping.md,Google 群组也是一个很好的来源 - https://groups.google.com/group/restkit。希望这一切都有帮助。
I agree - RestKit can do this, we've recently used it to do something similar in a recent project. We used a last-modified-date request header to indicate the last successful 'sync' time, which the server can use to return only the records modified since that date. A http 304 'not modified' status code was used to indicate no change when appropriate.
RestKit also includes a seeding facility, so you know up front the initial data set - you can seed it as the initial database easily, and fetch the updates, even upon first use of the application.
Some information I found useful regarding RestKit & CoreData mapping - https://github.com/RestKit/RestKit/blob/master/Docs/Object%20Mapping.md, and the Google group is a good source as well - https://groups.google.com/group/restkit. Hope this all helps.
首先:是的,
RestKit 可以很好地处理 CoreData。您所需要做的就是提供实体的映射,它就会为您完成工作。
关于选择性同步的第二件事,我真的建议检查 StorageRoomApp 这是一项很棒的服务,而且价格也不贵正是您所需要的。
他们有一个非常好的API,扩展了RestKit,非常容易使用,而且他们的支持也很棒。看看吧。
First of all: YES
RestKit handles CoreData very well. All you need to do is to provide mapping of your entities and it does the work for you.
For the second thing about selective sync, I really recommend checking StorageRoomApp it is a great, and not so expensive service that does exactly what you need.
They have a very good API that extends RestKit, it is very easy to use and their support is great. Take a look.