Latest in Apple

Image credit:

How iCloud works


During a recent edition of TUAW TV Live, the question of how iCloud works in applications came up. After some internal consultation, we came to the conclusion that Apple has fully announced this feature and that its workings would not be considered confidential.

In that spirit, here's an introduction to iCloud's internals summarized from material in my upcoming iOS 5 Developer's Cookbook expanded edition.

In its simplest form, iCloud is merely a special folder. It lives on the iOS device in /private/var/mobile/Library/Mobile Documents/. That folder hosts all application material that applications share to the cloud.

Applications have partial permission to read from and write to this folder. That permission is developer-specific. As with the password keychain, developers can share cloud data between applications.

For example, all apps developed by App Company X could share, view, and update the same document set. You cannot share data outside of your developer account. So my apps cannot see App Company X documents, and vice-versa.

The Mobile Documents folder is monitored by iOS. When files are modified, the device automatically uploads changes to the cloud. Those changes propagate out to all other devices registered to the same account. This is handled by a local OS service, and applications aren't directly involved.

Instead, applications subscribe to a variety of classes and notifications that allow them to know when changes occur. They can then resolve conflicts to bring local data into harmony with the iCloud versions.

How developers do this is up to them. They may choose a "most recent change wins" strategy. Or they may combine changes in some other manner. It's the application's job to ensure that data presented on one unit matches the data on other units, so long as there is network communication available to handle that conformance.

The tricky bits happen when a user drops out of communication. For example, you might edit a to-do list on a plane, when you have no net access, while your partner updates his or her to-do list in another city. Developers have worked for months on strategies for combining those changes and updating their documents to honor edits from both parties.

In the end, there's very little in the way of iCloud APIs. It's really just a folder that is synchronized to offsite-storage. The trick will be how well developers think about different ways that distance, connection, and time can affect the way documents in that folder must adapt to user updates.

From around the web

ear iconeye icontext filevr