简体   繁体   中英

Cloud sync between iPad/iPhone app

I have a Core Data app that will end up being an iPhone/iPad universal application.

I would like to implement cloud syncing so that an iPhone and an iPad both running the app could share data. I'm planning to use the recently released Dropbox API . Does anyone have any thoughts on the best way to go about doing this? The Dropbox API allows for apps to store files on the cloud. What I was thinking was to original store the database (sqlite) for the app on the cloud and then download that database, but I then realized that using that method would make it painfully difficult to merge changes (rather than replacing the whole database).

Any thoughts are appreciated. Thanks.

If you can get away with it, the easiest way to do synchronization (by far) is to have three copies of your data locally: the copy you last uploaded ("old"), the copy produced by local changes ("mine") and the copy now downloaded from the server ("theirs").

Then, sort all the records in all three files and walk through them one by one:

  • if old == mine, use theirs
  • else if old == theirs, use mine
  • else you have a conflict; do something about it (eg. always use mine, aka "last writer wins")

Note that "mine" or "theirs" or "old" might not exist. The rules above still apply in that case; if the result you choose is "does not exist", then you'll want to delete the record in the output file.

Finally, upload the resulting file back to the server so that it will be the "theirs" database for the next guy. Then copy the new file to your local "old" and "mine" databases.

(There are more space-efficient algorithms than the above... but there aren't any easier ones :) And disk space is pretty cheap nowadays, particularly if you compress the files.)

You may want to use a different method for synchronization. What is the type of data that you will be dealing with?

I've had much success using a lightweight rails back-end.

You might look into GameKit to share data. Otherwise it seems like you'll just need to manage synchronization with an intermediate file server.

You probably want to export the data to some format other than the native sqlite format. If I were designing something like this, I think JSON would probably be my format of choice.

I haven't looked at the dropbox API, but they support uploading and downloading file differences, rather than the whole file, right? Depending on how the API works, maybe having your application understand their "diff" format and working with that might be easier...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM