iCloud for Unity – Documentation

iCloud for Unity

iCloud for Unity let’s you put your data in the cloud as easy as A.B.C.

Available from those stores:

v2.0.2 – Unity 3.5.7+ – Requires Unity iOS (Basic or Pro) or Unity Pro

iCloud for Unity is a Unity plugin for using iOS and Mac OS iCloud features in your projects. It allows you to store documents and data (in other words, files and preferences) using Apple’s iCloud storage for easy and reliable sharing between your iOS and Mac OS devices. iCloud for Unity provides you with a simple, intuitive and straight-forward application programming interface to manipulate files and folders in the cloud as well as key-value storage in the cloud. Because it implements fall backs for unsupported platforms, you can use this plugin for all your deployment targets and it will detect that iCloud is either unsupported or unavailable and will rely on local storage to continue to provide its services.

While iCloud storage is limited to Apple’s devices, it has several advantages over other cloud services. First of all, because this is Apple’s official solution, it is heavily promoted and often enabled as soon as the user activates his device for the first time. Therefore, we feel that for Apple devices this is the cloud storage solution that will have the most widespread use (fact: Apple had more than 300 million active iCloud users by Q1 2013). Once it is activated, users won’t need to provide additional login credentials or enable settings in your application to benefit from its features.

Then, contrary to other cloud services, iCloud is a system-wide feature of iOS and Mac OS, meaning you don’t have to wait for your files to be uploaded to the cloud and writing or reading files will be just as fast as local storage. This means that you can use it for anything ranging from simple preferences to save game files or high-resolution screenshots taking several megabytes (of course you want to be careful not using too much space). Your application will behave just like you’re saving your files and data locally (the actual upload and download to other devices will obviously take some time but will happen in the background even after you exit your app).


We are providing you with two interfaces to implement iCloud storage. On the one hand, JCloudDocument is used to manipulate files and folders in the cloud with methods that matches closely File.IO and Directory.IO using straightforward function names. On the other hand, JCloudData is used to store user/player preferences in the same manner as PlayerPrefs.

System Requirements: To use iCloud for Unity for iOS, you need a Basic or Pro license for Unity iOS. To use iCloud for Unity for Mac OS, you are required to have a Unity Pro license. This plugin has not been tested on versions of Unity earlier than 3.4 and therefore it is recommended that you update your project to at least this version before you proceed with using it. You also need to be a registered iOS Developer for iOS targets or a registered Mac OS Developer for Mac OS targets.
Target Requirements: iCloud for Unity will use cloud storage on devices using iOS 5.0+ or Mac 10.7.2+ with an active iCloud account. For all other platforms or operating system versions, it will fall back to local storage.
Important Note: iCloud features can only be used in applications that are intended for iOS App Store or Mac App Store release and will not work in applications distributed outside of Apple’s official app stores, except for devices that are registered for development purposes (this is an Apple restriction).

Important Note: You should be extra careful with what you decide to store in the cloud. You should only store documents and data that your users will benefit from being shared between devices. Any file or content that can be reproduced between devices without sharing should not be put in the cloud and should remain local. Reckless usage of iCloud storage could prevent you from getting your app on the iOS App Store or Mac App Store. Moreover, your users are more likely to delete your application if they notice it uses an unnecessarily large amount of their limited iCloud storage space.

Quick Start instructions

Quick-start instructions are a jump start for those that are already familiar with concepts of codesigning, provisioning profiles and entitlements and know how to configure an iOS or Mac OS project for iCloud. Should you have any issue with those instructions, you should read the in-depth detailed documentation in the following sections.

  • Make sure your OS X (10.7+) installation is up to date (Apple Menu > Software Updates).
  • Make sure you have Xcode installed and it is updated to the latest version (via Mac App Store, Mac/iOS Dev Center or Software Updates).
  • Make sure you have a valid Mac/iOS development or release provisioning profile setup.
  • You should backup and/or commit (version control) your project before you continue.
  • MacOS: Use Unity Entitlements Tool to add a post-process script that will codesign your app on each Mac OS build.
  • iOS: Enable entitlements in the built Xcode project and pick the matching provisioning profile for code signing.
  • Import iCloud Plugin package in your Unity project (untick Tutorial folder if you don’t want it).
  • You can check if iCloud is enabled and working using the PollCloudDocumentAvailability and PollCloudDataAvailability methods (please note that iCloud is not available in the editor and will always fall back to local storage — you should build your app to test iCloud).


Setting up your project for iCloud on iOS

Because iCloud relies on compliance of your application with Apple requirements, you need to tweak a few settings in your Unity project so that you can effectively use iCloud for development or release purposes. If you do not set up correctly your project, iCloud won’t be enabled for your application and this plugin will fall back to local storage.

Quick Start Instructions

  • Create or enable an AppID with iCloud in iOS provisioning portal.
  • Create or renew a provisioning profile using this AppID in iOS provisioning portal.
  • Download and install the new or updated provisioning profile.
  • In your Unity project, go to Player settings for iOS and set a valid Bundle Identifier that matches the AppID pattern.
  • Build your Unity project for iOS and open the resulting Xcode project.
  • In Xcode, enable entitlements and iCloud for you project and make sure code signing is using the appropriate profile.
  • You can now use iCloud in your Unity project. If you delete your Xcode project directory, you will need to reapply those settings in the new generated project.

Detailed Instructions

First of all, if you are not familiar with Apple development assets or don’t understand any of the next step, you should read the development assets’ section of Apple’s iOS App Development Workflow Guide. If you don’t already have one, you need to either create an AppID with iCloud enabled or enable iCloud on one of your available AppIDs. For iOS deployment, you should head to the App IDs – iOS Provisioning Portal page. Unless you are using a custom AppID, you can configure the Xcode generated wildcard AppID with iCloud.

To enable iCloud on any AppID, click ‘Configure’ under the ‘Action’ column, then enable the ‘Enable for iCloud’ checkbox and click the ‘Done’ button. Make sure you also have a valid provisioning profile that is using this AppID, as modifying AppIDs will invalidate associated profiles and you will need to renew them (to renew Xcode’s automatic wildcard provisioning profile, launch Xcode, open Organizer and under Devices tab pick any of your iOS development devices and click the ‘Add to Portal’ button). You can check, create and update provisioning profiles under the Provisioning Profiles – iOS Provisioning Portal page. Remember to download and install (drag and drop to Xcode) any updated or new provisioning profile so you can use it in your projects.

Once you have an AppID enabled for iCloud, you should check your iOS Player settings in your Unity project (Edit Menu > Project Settings > Player). Under the ‘Other Settings’ pane for iOS platform, make sure that your ‘Bundle Identifier’ matches the pattern of your AppID : if your AppID is a wildcard AppID in the form APPID.*, you can put anything here (though it is recommended you use something in the form of com.company.app) ; if it is a precise AppID such as APPID.com.mycompany.mycoolapp then your bundle identifier must be com.mycompany.mycoolapp (otherwise you won’t be able to pick the appropriate provisioning profile for building in Xcode).

You can now build your Unity project for iOS. Once your project is built and opened in Xcode, you need to make a one-time setup (unless you later delete your build directory then you’ll need to reapply those settings). In the project navigator (that lists all the files and frameworks in your project), click on the project itself (first element, title like ‘Unity-iPhone’ and subtitle like ’2 targets, iOS SDK x.y’), then in the center pane pick ‘Unity-iPhone’ under ‘Targets’ in the left-side list. On the top-side of the center pane, click ‘Summary’ from the horizontal list. Scroll down to the bottom of the center pane and enable ‘Use Entitlements file’, ‘Enable iCloud’ and ‘Use store with identifier’. Also click once the ‘+’ button in ‘Ubiquity Containers’ to add your bundle identifier. After that is done, on the top-side of the center pane, click ‘Build Settings’ from the horizontal list. Enable ‘All’ and ‘Combined’ from the horizontal list just below. Locate the ‘Code Signing’ drop-down in the list below and specifically the ‘Code Signing Identity’ drop-down contained inside. Now pick the provisioning profiles that are using our iCloud enabled AppID for Debug purposes and/or Release purposes. If the profile you are looking for is not in the list, it is either not installed on your computer or expired, or you bundle identifier does match the pattern of the associated AppID.

You can now build and run your app on your device with iCloud enabled. You can poll iCloud availability in any of your script using the PollCloudDocumentAvailability, PollCloudDataAvailability and PollCloudDictionaryAvailability methods.

Important Note: If you want your application to share documents and data between iOS and Mac devices, you must use identical iCloud key-value store identifier and iCloud container identifier for both targets.

Setting up your project for iCloud on OS X

Because iCloud relies on compliance of your application with Apple requirements, you need to tweak a few settings in your Unity project so that you can effectively use iCloud for development or release purposes. If you do not set up correctly your project, iCloud won’t be enabled for your application and this plugin will fall back to local storage.

Quick Start Instructions

Detailed Instructions

First of all, if you are not familiar with Apple development assets or don’t understand any of the next step, you should read the development assets’ section of Apple’s Tools Workflow Guide for Mac. If you don’t already have one, you need to either create an AppID with iCloud enabled or enable iCloud on one of your available AppIDs. For Mac OS deployment, you should head to the App IDs – Developer Certificate Utility page. Unless you are using a custom AppID, you can configure the Xcode generated wildcard AppID with iCloud.

To enable iCloud on any AppID, click ‘Configure’ button in the AppID’s line, then enable the ‘Enable for iCloud’ checkbox. Make sure you also have a valid provisioning profile that is using this AppID, as modifying AppIDs will invalidate associated profiles and you will need to renew them (to renew Xcode’s automatic wildcard provisioning profile, launch Xcode, open Organizer and under Devices tab pick any of your Mac OS development devices and click the ‘Add to Portal’ button). You can check, create and update provisioning profiles under the Provisioning Profiles – Developer Certificate Utility page. Remember to download and install (double click on profile file) any updated or new provisioning profile so you can use it in your projects. Installed profiles should appear in Mac OS System Preferences under the Profiles category.

You’ll then need to enable code signing, entitlements and sandboxing on your Mac OS builds so that it can use iCloud. To facilitate and automate this process, we have created a small app called Unity Entitlements Tool that tweaks your Unity project by adding a post-process script that will automatically codesign your application on each build. Follow the tools instructions and make sure you pick the provisioning profile you have just configured and installed for eihter development or release purposes.

Important Note: If you want your application to share documents and data between iOS and Mac devices, you must use identical iCloud key-value store identifier and iCloud container identifier for both targets.

JCloudDocument – Files and Directories in the cloud

JCloudDocument class allows you to easily manipulate files and directories in the cloud. Documents are any type of file or folder contained in your application specific documents container that is hidden from standard file and directory input/output mechanisms.

Because of this, when specifing paths you must provide a relative path (starting with the name of the file or directory without ‘/’ character at the beginning) and need not to worry about path resolution to your document container.

Availability: You can test if JCloudDocument will use cloud storage with the PollCloudDocumentAvailability() method.

Fallback: When iCloud is not available or not supported on the target platform, JCloudDocument will fall back to local storage using Unity’s persistent data path. If the user enables iCloud but already has local files and directories stored using JCloudDocument, the plugin will automatically move those to the cloud as you access them with JCloudDocument.

Important Note: When specifying paths using JCloudDocument, all paths are relative to the documents container and should not start with a slash ‘/’ character (for example a valid path would be “Screenshots/screen01.png” while “/Screenshots/screen01.png” will always fail).
Important Note: As with System.IO .NET methods, you are responsible for checking and creating directories when you attempt to create a file in a subfolder that has not been created yet. Trying to create a file in a inexistant subfolder will fail.
How-To: You can see a full list of JCloudDocument methods at the Plugin Reference or examples of JCloudDocument usage cases at the Code Examples.

JCloudData – PlayerPrefs using iCloud key-value store

JCloudData allows you to store small chunks of data such as user data or player preferences. It mirrors the PlayerPrefs class from Unity in its form and functionalities. Because it uses Apple’s official iCloud key-value store, it comes with some limiations on size for the entire key-value storage as well as the length of keys.

The key-value store should and will not exceed 1 MB of data, any attempt to store more data will fail ; and keys should not exceed 64 bytes in UTF-8 encoding, providing keys longer than 64 bytes will fail. In addition, you cannot store more than 1024 keys.

Availability: You can test if JCloudData will use cloud storage with the PollCloudDataAvailability() method. This will actually return true even if iCloud is disabled (on devices where it’s available) because iOS handles this automatically (it will push data to iCloud if the user enables it).

Fallback: When iCloud is not available or not supported on the target platform, JCloudData will either fall back to NSUserDefaults or PlayerPrefs.

Important Note Because of iCloud’s key-value store limitations in terms of size (1 MB for the entire store, 64 bytes per key in UTF-8 encoding), this should be used for really small amounts of data. Attempting to write data that exceeds quotas will fail and old values for pre-existent keys will remain in place.
How-To: You can see a full list of JCloudData methods at the Plugin Reference or examples of JCloudData usage cases at the Code Examples.