Coding Guidelines

The iCloud Fundamentals guide has a table that compares Document Storage to the Key-Value Store(Table 1-1). In contrary to Mobile Documents, the Key Value Store should be considered Always effectively available. Even if a user isn't connected to iCloud or in the offline mode. Data will be uploaded later when it's possible.


Write data:

iCloudManager.instance.setString ("TestStringKey", "Hello World");
iCloudManager.instance.setFloat ("TestFloatKey", 1.1f);

string msg = "hello world";
System.Text.UTF8Encoding  encoding = new System.Text.UTF8Encoding();
byte[] data = encoding.GetBytes(msg);
iCloudManager.instance.setData ("TestByteKey", data);

Read Data

iCloudManager.OnCloudDataReceivedAction += OnCloudDataReceivedAction;
iCloudManager.instance.requestDataForKey ("TestFloatKey");

private void OnCloudDataReceivedAction (iCloudData data) {
    iCloudManager.OnCloudDataReceivedAction -= OnCloudDataReceivedAction;

	if(data.IsEmpty) {
		IOSNativePopUpManager.showMessage(data.key, "data is empty");
	} else {
		IOSNativePopUpManager.showMessage(data.key, data.stringValue);

Handling Conflicts

Any device running your app, and attached to a user’s iCloud account, can upload key-value changes to that account. To keep track of such changes, register for the HandleOnStoreDidChangeExternally  notification during app launch. And use it to detect which keys changed externally and update the corresponding data in the user defaults database. By doing this, your user defaults database always contains the correct configuration values. The iCloud key-value store simply becomes a mechanism for ensuring that the user defaults database has the most recent changes. The following code snippet shows how to prepare your app to use the HandleOnStoreDidChangeExternally Action.

iCloudManager.OnStoreDidChangeExternally += HandleOnStoreDidChangeExternally;
void HandleOnStoreDidChangeExternally (System.Collections.Generic.List<iCloudData> changedData) {
	foreach(iCloudData data in changedData) {
		Debug.Log("Cloud data with key:  " + data.key + " was chnaged");
		//update value for key

APA References


public class iCloudManager : ISN_Singleton<iCloudManager> {

	static event Action<ISN_Result> OnCloudInitAction;
	static event Action<iCloudData> OnCloudDataReceivedAction;
	static event Action<List<iCloudData>> OnStoreDidChangeExternally;

	//Public Methods
	void init();
	void setString(string key, string val);
	void setFloat(string key, float val);
	void setData(string key, byte[] val);
	void requestDataForKey(string key);


public class iCloudData  {

	public string key {get;}

	public string stringValue {get;}
	public float floatValue {get;}
	public byte[] bytesValue {get;}

	public bool IsEmpty {get;}


The full implementation example can be founded under the iCloudUseExample.cs script.