iCloud for Unity – Reference

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

JCloudDocument – Files and Directories in the cloud

File methods

public static JCloudDocumentOperation FileExists(string path);
Determines if a file exists at path. Should only be used in a coroutine.
Returned
JCloudDocumentOperation
members state:
bool finished
While this is false, keep yielding.
float progress
Not used by this method.
bool success
Failure can be caused by a invalid path or a plugin error.
object result
Object type
bool?
. True if file exists, false if it does not exist.
public static JCloudDocumentOperation FileDelete(string path);
Deletes file at path. Should only be used in a coroutine.
Returned
JCloudDocumentOperation
members state:
bool finished
While this is false, keep yielding.
float progress
Not used by this method.
bool success
Failure can be caused by a invalid path, inexistant file or a plugin error.
object result
Object type
bool?
. True if file was deleted, false means failed deletion (but file exists).
public static JCloudDocumentOperation FileWriteAllBytes(string path, byte[] bytes);
Writes bytes to the file at path. Should only be used in a coroutine.
Returned
JCloudDocumentOperation
members state:
bool finished
While this is false, keep yielding.
float progress
Not used by this method.
bool success
Failure can be caused by a invalid path or a plugin error.
object result
Object type
bool?
. True if file was written, false means failed write (plugin error).
public static JCloudDocumentOperation FileReadAllBytes(string path);
Reads bytes from file at path. Should only be used in a coroutine.
Returned
JCloudDocumentOperation
members state:
bool finished
While this is false, keep yielding.
float progress
This value varies from 0.0f to 100.0f while the operation is not finished.
bool success
Failure can be caused by a invalid path, inexistant file or a plugin error.
object result
Object type
byte[]
. Contains the file data as a byte array. Can be null.
public static JCloudDocumentOperation FileModificationDate(string path);
Get last modification date (in local time) for file at path. Should only be used in a coroutine.
Returned
JCloudDocumentOperation
members state:
bool finished
While this is false, keep yielding.
float progress
Not used by this method.
bool success
Failure can be caused by a invalid path, inexistant file or a plugin error.
object result
Object type
DateTime?
. File last modification date using local device time.
public static JCloudDocumentOperation FileCopy(string sourcePath, string destinationPath, bool overwrite);
Copies a file from a source path to a destination path. Set overwrite to true to allow the mechanism to replace the file at destination path if it already exists. Should only be used in a coroutine.
Returned
JCloudDocumentOperation
members state:
bool finished
While this is false, keep yielding.
float progress
This value varies from 0.0f to 100.0f while the operation is not finished.
bool success
Failure can be caused by a invalid path, inexistant source file or a plugin error.
object result
Object type
bool?
. True if file successfully copied, false if failed copy (either overwrite false and destination file already there or plugin error).
public static JCloudDocumentOperation FileMove(string sourcePath, string destinationPath, bool overwrite);
Moves a file from a source path to a destination path. Set overwrite to true to allow the mechanism to replace the file at destination path if it already exists. Should only be used in a coroutine.
Returned
JCloudDocumentOperation
members state:
bool finished
While this is false, keep yielding.
float progress
This value varies from 0.0f to 100.0f while the operation is not finished.
bool success
Failure can be caused by a invalid path, inexistant source file or a plugin error.
object result
Object type
bool?
. True if file successfully moved, false if failed move (either overwrite false and destination file already there or plugin error).

Directory methods

public static JCloudDocumentOperation DirectoryCreate(string path);
Creates a directory at path. Should only be used in a coroutine.
Returned
JCloudDocumentOperation
members state:
bool finished
While this is false, keep yielding.
float progress
Not used by this method.
bool success
Failure can be caused by a invalid path or a plugin error.
object result
Object type
bool?
. True if directory was created, false if creation failed (plugin error).
public static JCloudDocumentOperation DirectoryExists(string path);
Determines if a directory exists at path. Should only be used in a coroutine.
Returned
JCloudDocumentOperation
members state:
bool finished
While this is false, keep yielding.
float progress
Not used by this method.
bool success
Failure can be caused by a invalid path or a plugin error.
object result
Object type
bool?
. True if directory exists, false if it does not exist.
public static JCloudDocumentOperation DirectoryDelete(string path);
Deletes a directory at path. Should only be used in a coroutine.
Returned
JCloudDocumentOperation
members state:
bool finished
While this is false, keep yielding.
float progress
Not used by this method.
bool success
Failure can be caused by a invalid path, inexistant directory or a plugin error.
object result
Object type
bool?
. True if directory was deleted, false means failed deletion (but directory exists).
public static JCloudDocumentOperation DirectoryGetFiles(string path);
Gets a list of files at path. Should only be used in a coroutine.
Returned
JCloudDocumentOperation
members state:
bool finished
While this is false, keep yielding.
float progress
Not used by this method.
bool success
Failure can be caused by a invalid path, inexistant directory or a plugin error.
object result
Object type
string[]
. An array of file names, null means failed list fetching (but directory exists).
public static JCloudDocumentOperation DirectoryGetDirectories(string path);
Gets a list of directories at path. Should only be used in a coroutine.
Returned
JCloudDocumentOperation
members state:
bool finished
While this is false, keep yielding.
float progress
Not used by this method.
bool success
Failure can be caused by a invalid path, inexistant directory or a plugin error.
object result
Object type
string[]
. An array of directory names, null means failed list fetching (but directory exists).
public static JCloudDocumentOperation DirectoryModificationDate(string path);
Get last modification date (in local time) for directory at path. Should only be used in a coroutine.
Returned
JCloudDocumentOperation
members state:
bool finished
While this is false, keep yielding.
float progress
Not used by this method.
bool success
Failure can be caused by a invalid path, inexistant directory or a plugin error.
object result
Object type
DateTime?
. Directory last modification date using local device time.
public static JCloudDocumentOperation DirectoryCopy(string sourcePath, string destinationPath, bool overwrite);
Copies a directory from a source path to a destination path. Set overwrite to true to allow the mechanism to replace the directory at destination path if it already exists. Should only be used in a coroutine.
Returned
JCloudDocumentOperation
members state:
bool finished
While this is false, keep yielding.
float progress
This value varies from 0.0f to 100.0f while the operation is not finished.
bool success
Failure can be caused by a invalid path, inexistant source directory or a plugin error.
object result
Object type
bool?
. True if directory successfully copied, false if failed copy (either overwrite false and destination file already there or plugin error).
public static JCloudDocumentOperation DirectoryMove(string sourcePath, string destinationPath, bool overwrite);
Moves a directory from a source path to a destination path. Set overwrite to true to allow the mechanism to replace the directory at destination path if it already exists. Should only be used in a coroutine.
Returned
JCloudDocumentOperation
members state:
bool finished
While this is false, keep yielding.
float progress
This value varies from 0.0f to 100.0f while the operation is not finished.
bool success
Failure can be caused by a invalid path, inexistant source directory or a plugin error.
object result
Object type
bool?
. True if directory successfully moved, false if failed copy (either overwrite false and destination file already there or plugin error).

Miscellaneous methods

public static bool PollCloudDocumentAvailability();
Determines if iCloud document storage is available. Returns true if iCloud document storage is available or false if it either is unavailable or unsupported (which means JCloudDocument will fall back to local storage).

Miscellaneous members

public static bool AcceptJailbrokenDevices;
Set this to false if you do not wish jailbroken iOS devices to use iCloud features (there have been some reports of issues with iCloud and jailbreaking). By default, this member is set to true and iCloud will be used on jailbroken devices. Please note that there is no reliable way to detect jailbroken devices and this feature may not work on some devices.

JCloudData – PlayerPrefs using iCloud key-value store

Data manipulation methods

public static void SetInt(string key, int value);
Sets the integer value for the specified key. Returns nothing.
public static void GetInt(string key);
Gets the integer value for the specified key. Returns the integer value or 0 if key-value does not exist.
public static void GetInt(string key, int defaultValue);
Gets the integer value for the specified key. Returns the integer value or the specified default value if key-value does not exist.
public static void SetFloat(string key, float value);
Sets the float value for the specified key. Returns nothing.
public static void GetFloat(string key);
Gets the float value for the specified key. Returns the float value or 0.0f if key-value does not exist.
public static void GetFloat(string key, float defaultValue);
Gets the float value for the specified key. Returns the float value or the specified default value if key-value does not exist.
public static void SetString(string key, string value);
Sets the string value for the specified key. Returns nothing.
public static void GetString(string key);
Gets the string value for the specified key. Returns the string value or “” (empty string) if key-value does not exist.
public static void GetString(string key, string defaultValue);
Gets the string value for the specified key. Returns the string value or the specified default value if key-value does not exist.
public static void HasKey(string key);
Determines whether a key-value exists or not. Returns true if key-value exists or false if key-value does not exist.
public static void DeleteKey(string key);
Deletes the specified key-value. Returns nothing.
public static void DeleteAll();
Deletes the entire key-value store. Returns nothing.
public static void Save();
Saves the entire key-value store to the cloud. Returns nothing.

Conflict resolution methods

public static bool RegisterCloudDataExternalChanges(Component componentOrGameObject);

Registers the component or game object for notifications when external changes occur in JCloudData key-value store. Returns true if component or game object was successfully registered for notifications, false if it failed (probably means that iCloud is not enabled or not available).

The component or game object that has registered for notifications should implement the method
void JCloudDataDidChangeExternally(JCloudDataExternalChange change)
which gets called when external changes occur. This method only works when iCloud is available and enabled.
JCloudDataExternalChange
members:
JCloudDataChangeReason Reason
Contains the reason returned by iCloud for the change.
JCloudKeyValueChange[] ChangedKeyValues
An array of key-value changes with old and new values.
JCloudDataChangeReason
enum values (descriptions from Apple documentation):
JCloudDataServerChange
A value changed in iCloud. This occurs when another device, running another instance of your app and attached to the same iCloud account, uploads a new value.
JCloudDataInitialSyncChange
Your attempt to write to key-value storage was discarded because an initial download from iCloud has not yet happened. That is, before you can first write key-value data, the system must ensure that your app’s local, on-disk cache matches the truth in iCloud. Initial downloads happen the first time a device is connected to an iCloud account, and when a user switches their primary iCloud account.
JCloudDataQuotaViolationChange
Your app’s key-value store has exceeded its space quota on the iCloud server.
JCloudDataAccountChange
The user has changed the primary iCloud account. The keys and values in the local key-value store have been replaced with those from the new account, regardless of the relative timestamps.
JCloudKeyValueChange
members:
string Key
Key name.
JCloudDataValueType OldValueType
Contains the data type of the old value. You can also use typeof on OldValue.
object OldValue
Old value. Null if key wasn’t set.
JCloudDataValueType NewValueType
Contains the data type of the new value. You can also use typeof on NewValue.
object NewValue
New value. Null if key isn’t set anymore.
JCloudDataExternalChange
enum values:
JCloudDataNull
Null. Key-value wasn’t set.
JCloudDataInt
Object of type int. Cast using (int)Value (check for null) or Value as int?.
JCloudDataFloat
Object of type float. Cast using (float)Value (check for null) or Value as float?.
JCloudDataString
Object of type string. Cast using (string)Value or Value as string.
public static bool UnregisterCloudDataExternalChanges();
Unregisters the component or game object for notifications when external changes occur in JCloudData key-value store. Returns true if component or game object was successfully unregistered for notifications, false if it failed (probably means that iCloud is not enabled or not available, or that the component wasn’t registered for notifications in the first place).

Miscellaneous methods

public static bool PollCloudDataAvailability();
Determines if iCloud data storage is available. Returns true if iCloud data storage is available or false if it either is unavailable or unsupported (which means JCloudData will fall back to local storage with NSUserDefaults or PlayerPrefs depending on the platform).

Miscellaneous members

public static bool AcceptJailbrokenDevices;
Set this to false if you do not wish jailbroken iOS devices to use iCloud features (there have been some reports of issues with iCloud and jailbreaking). By default, this member is set to true and iCloud will be used on jailbroken devices. Please note that there is no reliable way to detect jailbroken devices and this feature may not work on some devices.