tags:

views:

50

answers:

2

My app parses XML from remote server and store the objects in Core Data(SQLite storage). So that user can browse the material when OFFLINE by reading from local storage.

User may make changes to objects when browsing offline which gets stored locally in Core Data SQLite store. Another User makes some changes to object on Remote server and it is stored there. Now when I detect internet connection, my app should sync my local storage with remote server. Which means remote server is updated with changes I made to my Core Data(SQLite storage) when I was offline and my local storage - Core Data(SQLite storage) needs to be updated with what ever changes other user made to remote server.

For example there is a forum and it is stored in my local storage so that I can read and reply when I am traveling. When later on internet is accessible. My app should automatically put all my replies stored in core data to remote server and also bring other posts on remote server into my local storage.

Remote server is sending XML which I'm parsing and storing in Coredata. My problem is how to sync it ? How both ways communication happens when there is a change? How to sync only data which has changed and not to IMPORT whole remote server DB and vice-versa ?

A: 

One solution could be

  • iphone syncs the changes to the server
  • server merges the new and old stuff
  • iphone gets the new changes (from the merge) from the server

So let the server be the master which should know how to merge stuff and the clients should only download the data incrementally after some changes.

brutella
Thanks Kiran and brutella. Trying to implement it and see how it works.
Ravi
+2  A: 

I know one of the way to do it..

  1. add one more field to your local and server database. i.e. Timestamp.
  2. when user change data on the local database change the Timestamp to current time. do same on the server..i.e. When someone edit data on the server change Timestamp to current time.
  3. When user connects to internet... check local Timestamp to Server timestamp.. case 1 Both are same - Nothing to do case 2 local time > server time - use sql to get all the data having timestamp greater than server timestamp.. and upload it on the server... case 3 local < server .... get all the records greater than the local timestamp and add it to the local database..

I am not sure if there is any better way... but this surely works...

KiranThorat