Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 500
indragie Avatar asked Jun 02 '10 23:06

indragie


People also ask

How do I sync apps between iPhone and iPad?

The Solution: iCloudOpen the Settings app on one device, tap your name to open the Apple ID screen, then select iCloud. Turn on the toggle switches next to every category of app and content that you want to sync between the iPhone and iPad. Repeat this process with the second device.

How do I share iCloud between iPhone and iPad?

Go to Settings > [your name]. Tap Family Sharing. Tap iCloud+. Follow the steps to share your existing plan.

How do I sync apps across all Apple devices?

The first time you set up syncing, you must connect your device to your Mac using a USB or USB-C cable. After you connect the device, the device icon appears in the Finder sidebar and selecting the icon displays syncing options. You then select which items to sync.


2 Answers

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.)

like image 109
apenwarr Avatar answered Sep 27 '22 18:09

apenwarr


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.

like image 25
jessecurry Avatar answered Sep 27 '22 18:09

jessecurry