What is a good solution to synchronize data between iOS apps?

marzapower picture marzapower · May 27, 2011 · Viewed 11.5k times · Source

I am developing an application, whose data management is realized through Core Data, and I am studying how to implement a feature to synchronize data between two different devices (even between iDevices and Mac's eventually).

Until now I haven't found nothing interesting or useful, so I am asking you for a good start point, a guide, or a model to follow. Did you ever realize something like this?

Update

I've started a bounty on this question. Synchronization could be a difficult task on iOS, but come on, there's plenty of apps out there that offer device-to-device sync functionalities. My question is: how they do this? What's the best approach? What are the different solutions?

Update 2

This question is surely outdated, right now, since iCloud has been released almost a year ago. I'd like to keep it alive since it can give interesting insights on mobile data synchronization between devices.

Answer

octy picture octy · Jun 2, 2011

If you want to do it yourself, this can be a very nice, yet challenging exercise. I don't know of any 3rd party frameworks that facilitate P2P connectivity between "iDevices", other than the ones below, from Apple. You can do some research along those lines if you don't want to re-invent the wheel. I am answering based on my (little) experience with implementing a syncing service via an app server - the principles must be more or less the same with a P2P approach.

The first step would be to design a protocol for syncing your data. Questions you might have to answer for yourself:

  • What do I need to understand about data synchronization?
  • Which part of my Core Data model do I want to sync? Should I make changes to my current model to facilitate syncing?
  • What serialization/deserialization mechanism will I use?
  • How will I be able to uniquely identify entities across multiple devices?
  • How will I version my data? How can I tell which entities need to be sync'ed?
  • Do I need to be able to revert a syncing operation?
  • How will I keep track of sync progress and how will I handle failures and exception cases? How will I notify the user of these?
  • Do I prefer to sync "incrementally" (parts of my model) or "globally" (the whole model at once)?
  • How often will the user need to sync between devices?
  • Are there any security considerations? Do I need encryption?
  • etc.

This is barely scratching the surface. You will definitely find more things to think about as you move forward.

Next, determine how you want to connect between devices. You seem to prefer an over-the-air solution, the P2P kind. For that, I would start by looking at these tools:

  • GameKit (this framework has APIs for establishing connectivity between devices over Bluetooth)
  • Bonjour (the Apple protocol for device discovery over a network - see the BonjourWeb sample application) + BSD sockets

Pick whichever tool(s) you feel most comfortable with and based on your design decisions discussed earlier. I can't help you there, as I don't have any experience with either of them. As Morpheus said:

I can only show you the door. You're the one that has to walk through it.

Sorry, little humor :)

Finally, decide on a solution to implement your syncing mechanism. You could e.g. choose a client-server model (one device will listen for a connection and another one will initiate it).

More relevant documentation:

I hope this gives you a starting path.