需要帮助RestKit数据同步方案 [英] Need help for RestKit data sync scenario

查看:128
本文介绍了需要帮助RestKit数据同步方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用RestKit for iOS To app。我已经使用restkit完成了以下操作:
1.以json格式从rest api中提取服务器对象。
2.删除服务器上不再存在的核心数据中的孤立对象。

I am using RestKit for an iOS To app. I already had done following using restkit: 1. Pull server objects from rest api in json format. 2. Delete orphan objects in core data which are no longer present on server.

现在我必须构建以下方案,如果互联网可用设备和用户正在添加一个新的数据项,然后我应该先做什么,即我应该先在本地存储新数据,然后发布到服务器或首先将数据发布到服务器并将其拉回到设备上?

Now i have to build the following scenario, if the internet is available on the device and user is adding a new data item,then what should i do first i.e should i store the new data first locally and then post to server or first i post the data to server and the pull it back on device ?

其次,如果互联网在设备上不可用,用户插入新数据项,则在本地保存数据,在互联网上可用性如何将新添加的数据项发布到服务器,即采用何种方法我应该遵循并且如果restkit可以帮助我解决这个问题吗?

Secondly if the internet is not available on device and user inserts a new data item then saves data locally, On internet availability how do i post newly added data items to the server i.e what approach should i follow and if restkit can help me tackling this scenario ?

推荐答案

RestKit包括可达性监控(实际上是AFNetworking的一部分)。因此,您可以设置在状态更改时运行的块:

RestKit includes reachability monitoring (actually part of AFNetworking). So you can set a block to be run when the status changes:

[objectManager.HTTPClient setReachabilityStatusChangeBlock:...

通常,在所有情况下都会在本地存储物品。当项目被推送到服务器时,在项目上设置同步日期或标志以确认它已被更新。

Generally, store the item locally in all cases. When the item has been pushed to the server, set the sync date or a flag on the item to confirm that it has been updated.

这是一个更广泛的问题如何管理服务器的本地修改和更新。您可能希望整体方案列出对象并将更新推送到服务器,并让服务器响应设置每个项目的同步时间。如果您使用2个日期(一个用于最后一个本地修改,一个用于远程同步),那么模型上的快速谓词提取将告诉您哪些对象是脏的并且需要被推送到服务器。

This is really a broader question about how you manage local modifications and updates to the server. You may want an overall scheme to list the dirty objects and push updates to the server and have the server response set the sync time for each item. If you use 2 dates (one for the last local modification and one for the remote sync) then a quick predicate fetch on the model will tell you which objects are dirty and need to be pushed to the server.

这篇关于需要帮助RestKit数据同步方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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