Umair
Umair

Reputation: 398

Need help for RestKit data sync scenario

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 ?

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 ?

Upvotes: 1

Views: 289

Answers (1)

Wain
Wain

Reputation: 119031

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.

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.

Upvotes: 2

Related Questions