private void ModifyRecord()
    {
        // There's no "modify record" operation in cloud-kit. To modify a record
        // you just re-save a record whose 'RecordChangeTag' matches the tag on
        // the server. This ensures that you are always modifying the most recent
        // version of the record.

        // For a single client application, this should always be the same

        // So let's change a few values and re-save the record

        // Cloudkit stores both fixed and floating percision types in the same
        // Number type
        record.SetInt(UnityEngine.Random.Range(0, int.MaxValue), "MyNumber");
        record.SetDouble(UnityEngine.Random.Range(0f, float.MaxValue), "MyNumber");

        // You can also store arbitrary byte data
        byte[] bytes = Encoding.ASCII.GetBytes("Test Buffer");
        record.SetBuffer(bytes, "TestBufferKey");

        // You can't change the type of a field you set previously
        // This would generate an error...
        // record.SetInt(0, "MyField");

        database.SaveRecord(record, OnRecordModified);
    }
    private void Run()
    {
        Debug.Log("Example 6 - Per Record Progress");

        database = CKContainer.DefaultContainer().PrivateCloudDatabase;

        // Let's create 5 files at 1MB a piece
        // So we have enough data to see some upload progress

        // BTW CloudKit recommends that if your data exceeds 1MB you should put
        // it inside a CKAsset

        for (int i = 0; i < numFiles; i++)
        {
            var    record = new CKRecord("BigFile");
            byte[] bytes  = new byte[1000000];
            record.SetBuffer(bytes, "bytes");

            records[i] = record;
        }

        var op = new CKModifyRecordsOperation(records, null);

        op.Configuration.QualityOfService = NSQualityOfService.UserInitiated;

        op.PerRecordProgressBlock       = OnPerRecordProgress;
        op.PerRecordCompletionBlock     = OnPerRecordComplete;
        op.ModifyRecordsCompletionBlock = OnRecordsSaved;

        database.AddOperation(op);
    }
Beispiel #3
0
    public void Can_set_and_retrieve_buffer_by_key()
    {
        byte[] bytes = Encoding.ASCII.GetBytes("a bunch of bytes");

        var record   = new CKRecord("record_type");
        var bytesKey = "bytes_key";

        record.SetBuffer(bytes, bytesKey);

        Assert.AreEqual(record.BufferForKey(bytesKey), bytes);
    }
Beispiel #4
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));
        }
    }