void Run()
    {
        Debug.Log("Example 4 - CKAsset");
        database = CKContainer.DefaultContainer().PrivateCloudDatabase;

        var record = new CKRecord("MyType");

        // CloudKit recommends if your data is larger than 1MB that you store
        // it as an asset...
        // our example won't be anything close to 1MB, but it'll illustrate the
        // technique

#if UNITY_TVOS
        string path = Path.Combine(Application.temporaryCachePath, "Asset.bytes");
#else
        string path = Path.Combine(Application.persistentDataPath, "Asset.bytes");
#endif

        byte[] bytes = Encoding.ASCII.GetBytes("AssetData");
        File.WriteAllBytes(path, bytes);

        // Assets have to be files, so you pass it the filepath to something
        // in the user's data directory
        // the asset will be stored in cloudkit, with a URL for retrieval

        var fileurl = NSURL.FileURLWithPath(path);
        record.SetAsset(new CKAsset(fileurl), "MyAsset");

        database.SaveRecord(record, OnRecordSaved);
    }
Ejemplo n.º 2
0
    public void Can_set_and_retrieve_asset_by_key()
    {
        var record   = new CKRecord("record_type");
        var asset    = new CKAsset(NSURL.URLWithString("file:///someasset.bytes"));
        var assetKey = "asset_key";

        record.SetAsset(asset, assetKey);

        Assert.AreEqual(record.AssetForKey(assetKey), asset);
    }
Ejemplo n.º 3
0
    public void All_keys_has_all_the_keys()
    {
        var record = new CKRecord("record_type");
        var keys   = new string[] { "string_key", "bool_key", "int_key", "double_key", "buffer_key", "asset_key", "reference_key" };

        record.SetString(keys[0], "string_value");
        record.SetInt(1, keys[1]);
        record.SetDouble(1f, keys[2]);
        record.SetBuffer(new byte[] { }, keys[3]);
        record.SetAsset(new CKAsset(null), keys[4]);
        record.SetReference(new CKReference(new CKRecordID("record"), CKReferenceAction.DeleteSelf), keys[5]);

        var allKeys = record.AllKeys();

        foreach (var key in allKeys)
        {
            Assert.IsTrue(allKeys.Contains(key));
        }
    }