iCloud.*

Overview

The iCloud plugin enables access to Apple's iCloud APIs and provides instruments to synchronize data across a user's devices.

Important

While iCloud is part of the iOS operating system, users may not log in with their iCloud account, or a user may choose to disable iCloud entirely. Thus, it's important that users can interact with your app even if iCloud is not enabled.

iCloud Storage/Sharing

iCloud provides three distinct ways of storing and sharing data:

Key-Value Storage

Key-Value Storage (KVS) is the easiest aspect of iCloud to use and Apple recommends that all apps benefit from its implementation. Essentially, it provides the ability to associate data (values) with keys (strings). These key-value pairs are synchronized across all of the user's iCloud-enabled devices, allowing you to retrieve specific data using the associated key.

Note that storage space for KVS is strictly limited. You can declare a maximum of 1024 keys and the total size of all values should be less than 1 MB. Keys should be less than 64 symbols (bytes). You may opt to store all data in a single key with a large set of data or divide the data into multiple keys — simply note that if a key-value pair is modified, it will be synchronized as a whole entity, so separating data across several keys may improve synchronization speed and minimize cellular data usage.

Documents in iCloud

Documents in iCloud is designed to synchronize files across a user's iCloud-enabled devices and the iCloud plugin provides APIs to read and write these files.

Note that the storage space for Documents in iCloud is limited to the user's iCloud Drive space. Also be aware that the user can manually delete specific stored files via the iOS settings screen, so your app should not assume that a certain file exists in iCloud storage.

CloudKit

CloudKit is the most recent addition to the iCloud framework. This is a distributed database where you can store records either privately and publicly. Private records can only be accessed by the user who created them, while public records are shared between users. Essentially, CloudKit is a very powerful tool for storing data as well as sharing data between users.

Enabling iCloud

Using iCloud requires certain settings within your app's provisioning configuration. You can not use a wildcard App ID with iCloud, so you must configure and use an explicit one (guide). To configure iCloud with your app, follow these basic steps:

Log into the Apple Developer portal, enter the Member Center, and navigate to the Certificates, Identifiers & Profiles dashboard.

Click on Identifiers under the desired platform. There you should see all of your apps listed. Select the app for which you want to add iCloud support and, below the list of services, click Edit.

In the list of services, select the iCloud checkbox.

Generate (or regenerate) all provisioning profiles that include the selected App ID. For details on this process, please refer to the Creating Provisioning Profiles section here.

iCloud Containers

In addition to the steps above, if you want to use Documents in iCloud or CloudKit, you must associate an iCloud Container with the app as follows:

In the Apple Developer portal, from the same section reached in the steps above, select Include CloudKit support in the iCloud row.

In the same row, click the Edit button. Here you can create a new iCloud Container or associate an existing iCloud Container with the app. If you are creating an iCloud Container for the first time, note that you'll need to create/register it first, then repeat this step to associate the new container with the app and iCloud.

Generate (or regenerate) all provisioning profiles that include the selected App ID. For details on this process, please refer to the Creating Provisioning Profiles section here.

Sharing Data

For Documents in iCloud and CloudKit, you can share the data between multiple apps. This is facilitated by associating a dedicated iCloud Container with each app via the Apple Developer portal as outlined in the steps above. From that point, Corona will automatically extract the container information during the build process for each platform in which iCloud is set to true:

If using only KVS, you can share data between different apps by specifying a kvstore-identifier in the iphone table of build.settings. This will override the default boolean true which simply enables KVS for the same app on the user's iCloud-enabled devices.