Archive for August 27, 2012


August 27, 2012 Comments off


As more and more people are buying multiple devices, it is natural to expect that they should all be able to access the same data.

This post is intended to cover some of the background about where your data is stored, and how syncing between devices might be achieved.

Data and Backups
First of all each device might run the same version of an app, however the data you are seeing only exists on the device itself. If you lose your device, or delete the app, you will of course lose your data too.

Apple provide two backup solutions (iTunes and iCloud), however all they do is allow you to store your apps and data on your computer or in the “cloud” for safety. They are not in themselves a way of sharing data (i.e. syncing) between devices.

Syncing (i.e. data synchronisation)
Syncing is actually VERY complicated. As the devices aren’t all running your app at the same time, you essentially need somewhere else to store your shared data. iCloud itself could be used for this purpose, as could Dropbox or any other cloud-based storage/server.

When do you write changes? You could do this every time you add or edit something, or you could batch up changes and write them when you are done. To me the best time to do this is when you close the app, however since you can’t run in the background for long, that rules out pretty much everything except iCloud. The latter is simply a local copy on your device, and the operating system (iOS) takes care of the rest.

Did I mention it was slow? Not the actual write itself, but copying data between devices. It can easily take 30 seconds or even minutes for your data to appear in the cloud, and then on other devices. And this assumes you have network connectivity (which you might not have).

This delay causes another major issue: handling conflicts. If two people are editing the same data at the same time, you somehow have to figure out what the end result should be. Asking the user what to do for each conflict would be too painful on a device as small as an iPhone.

Use Cases
This brings me on to why syncing is needed, and I think the answer depends on the app.

I can certainly understand that two people with a joint bank account might both want to add and edit transactions in the same database, which is probably the most complicated use case. But iCloud is not a great solution for this, as it is not designed to share data between users at all. It is there to make it easy for one person to see their data on multiple devices.

All of my apps already support data sharing using the backups feature. You basically make a backup on one device, copy the file to another device (iCloud makes this easy) and then restore it. I have therefore just spent most of the weekend heavily optimising this use case as follows …

1. If you have made any changes to your data, when you close the app a new backup is made and copied to iCloud. No user intervention needed.

2. When you are running the app, it will check to see if there are any newer backups available in the background. If so, a popup asks you to install it.

3. Backup management (i.e. automatically deleting older backups).

The single user use case is therefore solved with a SINGLE tap on the receiving device, with two conditions:

1. that you know you are essentially overwriting your data and not to go editing things on multiple devices at the same time (this eliminates the conflict resolution issue).

2. that you are aware of the amount of data you are copying (i.e. the whole database). The latter is fine on WiFi of course, especially for Hill Lists and Meter Readings.

To solve the multi-user use case, I need a better place to store the changes (probably not iCloud), and I need to optimise the amount of data being copied (e.g. only sending the changes themselves). For the record, I have a good handle on the last bit …