Search code examples
objective-ciosrestios5restkit

How to manage local changes after an offline period with Restkit


I am making an online/offline ios app using Restkit but i don't know to synchronise after an offline period.

I was thinking of this :

  • On offline, i update local managed objects and i push the field local_changes to true
  • When i got internet back, before each GET request, i send all models with local_changes = true using the PUT request
  • If it's a new item, i send a POST request.

My problem is that my GET request, doesn't wait the end of GET requests to be send, so i got old datas (Datas not modified).

What do you think of this? Did you find a better way to do that?


Solution

  • I realize this is late, but I have recently been searching for a good way to do this.

    I am currently using a method from the AFHTTPClient class called setReachabilityStatusChangeBlock:(void (^)(AFNetworkReachabilityStatus status))block. In my AppDelegate where I setup my Restkit objectManager, I am running this method on my AFHTTPClient object. Within the method, I have an if statement that checks for network reachability. If it is not reachable, I save the current date in my AppDelegate. If it is reachable, and self.offline != nil, then you know that you just came back online.

    At this point you should be able to check the 'updatedAt' fields on your entities (with NSPredicates) to see if they have been updated or created later than the last time you went offline. Then you can PUT/POST accordingly.