File synchronisation

One of the least exciting but nonetheless necessary tasks involved with writing a content creation app for iOS is implementing a way to get data in and out of the app. While adding iTunes file sharing support is trivially easy, it’s pretty much expected that your app will also support online file storage services like Dropbox and WebDAV, which involves a lot more work. Most productivity apps on the iPad support this, so I had a look at number of them to see how they do it.

I found three main approaches:

  • Store all the documents locally, and provide import and export options for transferring individual documents between the iPad and the server. I don’t like this approach, because it means that if you’re regularly going back and forth between your computer and your iPad, you have to manually do the import/export each time, which is a pain.
  • Use iCloud. This is fine if you only ever want to access documents from the same app you created them in, the app is available for both your iPad/iPhone and your Mac, and the app supports iCloud on both platforms. But there’s no generic way of getting at your files from a PC or Mac, which I think makes it pretty useless. iWork documents are an exception, but even then you can only access them through a web interface, which doesn’t provide automatic synchronisation.
  • Allow access to files directly from the server, downloading them as necessary, and uploading them when they are saved.

I decided to go with this third approach, since it allows you to keep all your documents in one place and access them from anywhere – without the hassle of manually copying them back and forth all the time. But I noticed a couple of problems with the way in which the apps I looked at achieved this:

  • After closing a document, no local copy is kept on the iPad. It has to be re-downloaded each time you open it, even if it hasn’t changed on the server. Worse, you can’t access it offline – if you want to make some edits to your document on the train to work, you’re out of luck.
  • When saving a file, you are forced to wait for the upload to complete before you can carry on with your work.

In UX Write, I’ve implemented a file syncing mechanism similar to that of the PC and Mac Dropbox client. It works as follows:

  • UX Write keeps a local copy of any file you’ve previously opened. At regular intervals, or when you press “refresh”, it checks to see if these files have changed on the server and downloads any updated versions – in the background. You can also tell it to maintain a complete local copy of specific folders from your account.
  • If you try to open a file and there’s already a local copy of the latest version, it will open immediately.
  • When you save a file, it is written to local storage immediately, and uploaded in the background, while you continue with your work. If you’re not connected to the Internet at the time, it will upload the file later on, as soon as it gets a chance.
  • If the file has been modified independently on both the server and your iPad, you’ll be notified and given a chance to save your copy under a different name so you can later reconcile the differences.

The screenshot above shows what the file management interface looks like. Files that have a copy stored locally are shown in black, and files that exist on the server but not on the iPad are shown in grey. The icon to the right of each file shows its synchronisation status; the green ‘+’ over the iPad in some of these icons indicates that the file has been modified locally and is scheduled to be uploaded as soon as any other transfers have completed.

I’ve implemented these features in a generic manner which is not specific to any particular storage service, so it’s fairly easy for me to add support for new services. The first release of UX Write will support Dropbox and WebDAV, with other services being included in the future.