Developers can leverage iCloud for common ground storage of information specific to an iOS app.
As more users become multi-device dependent, it is important to understand iCloud and its benefits. Apple's iCloud is a cloud storage service - launched in October 2011 - with the intent of providing a common place to store information to be shared across devices. Additionally, iCloud offers a non-tethering wireless solution for backing up iOS devices. Developers, however, can leverage iCloud for "common ground" storage of information specific to an iOS app. Whether you deploy specific IOS apps for each mobile device, or use the "universal app" approach as described in this article, iCloud can help streamline the development process.
The 30,000-foot view
From the end-user's perspective, iCloud enabled devices are always in sync. While a user's documents, photos, music, and movies are stored on iCloud and shared across devices, the ability to synchronize a workflow is one of the more useful capabilities. In this context, a "workflow" can be described as an end-to-end process, or a sequence of events passing from initiation through completion - such as reading a book. As you read a book, for example, the sequence of events includes turning pages.
The built-in iBooks app is a great example of a synchronized workflow in action. When a user purchases a book within the iBooks app, the content is immediately downloaded to each device registered under the same account. As the user interacts with the book (flips pages, leaves bookmarks, etc.), information is stored on iCloud. This information enables the user to pick up where they left off on any of their iCloud-enabled devices.
Early versions of iOS devices required users to physically connect the device to a computer running iTunes for backing up or restoring apps and device settings. Today, the devices have the ability to wirelessly backup and synchronize information - such as music, movies, photos, video, device settings, and app data. Developers can store application-specific information to iCloud to ensure a consistent experience across each device supported by the app. High scores, settings, and preferences for an iOS game app are perfect candidates for iCloud storage.
From the control tower
Every developer has the ability to integrate with iCloud. The first step, of course, is to determine the type(s) of storage you would like to leverage. Currently, iCloud offers three types of storage, and depending on your specific needs, you may choose several options:
- Key-value storage is used for storing information, such as app state, or settings. The purpose of using key-value storage is to provide "common ground" for any information intended to be shared across all iCloud-enabled devices running an instance of your app.
- Document storage is used for storing human-readable documents, such as spreadsheets, drawings, and word-processing documents. Files are automatically synchronized between iOS and OS X devices.
- Core Data storage is used for remote, shared storage for any of the three persistent native file types: binary, SQLite, and XML. While binary and XML files require the constant transfer of files between devices, SQLite only transfers changes - using a data replication approach - making it a more efficient choice.
Preparing your app for iCloud
A few additional steps are necessary to include the features and benefits iCloud in your next great app. As with any iOS app, you must create a device provisioning profile. This process is described in detail in the Apple Developer's document, Creating and Downloading Development Provisioning Profiles.You can enable iCloud services for a specific app from within the "Certificates, Identifiers & Profiles" section of the Provisioning Portal. There are a series of checkboxes - each representing services you would like to enable. The current suite of services designed to enhance you app include: Data Protection, Game Center, iCloud, In-App Purchase, Passbook, and Push Notifications (Figure A).
The name-value pairs contained within this file - including the iCloud-specific settings - can be added by selecting the "Enable iCloud" checkbox shown in Figure B.
To use iCloud Key-value storage, select the Key-Value Store option. To enable document storage, including Core Data storage, you must configure ubiquity containers. A ubiquity container is the local representation of your app's iCloud storage. An iCloud-enabled app maintains a local cache of the information stored on the cloud. This allows the user to continue to work even when unable to connect to a network.
Choosing the proper iCloud storage type is important. The key-value storage is the easiest to implement, and can provide a consistent user experience across all iCloud-enabled devices. There is a 1MB storage limit per app to use for key-value storage.
Document storage is limited only by the space available in the user's iCloud account. Considering a user's storage is limited, Apple recommends only saving necessary information to iCloud. User documents, preferences, and app state are examples of information that should be stored on iCloud. Temporary files and cache files, for example, should never be stored on iCloud.
Developers have been slow to realize the benefits of iCloud. Game developers were the early adopters, followed closely by several apps leveraging the device-synchronization capabilities of iCloud. Apple provides a plethora of information regarding the process for developing an iCloud-enabled iOS app. Today, many apps are taking full advantage of iCloud. With a few extra steps, you too can get your head in the iCloud.