开发者

Cloud sync between iPad/iPhone app

开发者 https://www.devze.com 2023-01-02 15:15 出处:网络
I have a Core Data app that will end up being an iPhone/iPad universal application. I would like to im开发者_如何学JAVAplement cloud syncing so that an iPhone and an iPad both running the app could s

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

I would like to im开发者_如何学JAVAplement 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...

0

精彩评论

暂无评论...
验证码 换一张
取 消