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);
    }
    void Run()
    {
        //var testDisposable = new TestDisposable();

        //Debug.Log("made dispasable: " + testDisposable);

        //StartCoroutine(WaitABit());
        var op = new CKModifyRecordsOperation(null, new CKRecordID[] {
            new CKRecordID("1CB545B1-7CA3-423E-A215-67DA56578270"),
            new CKRecordID("321A8AD3-0FA9-40C3-8D76-D76328A0A7F1")
        });

        database = CKContainer.DefaultContainer().PrivateCloudDatabase;

        Debug.Log("Setting callback");
        op.ModifyRecordsCompletionBlock = (records, recordIds, error) =>
        {
            Debug.Log("Modify records done");
        };

        //Debug.Log("Setting QoS");
        op.Configuration.QualityOfService = NSQualityOfService.Default;

        database.AddOperation(op);

        StartCoroutine(WaitABit());
    }
示例#3
0
    // Start is called before the first frame update
    IEnumerator Start()
    {
        Debug.Log("Example 9 - Subscriptions");

        Debug.Log("Requesting notification token");

        ICloudNotifications.RequestNotificationToken((tokenBytes, error) => {
            if (error != null)
            {
                Debug.LogError("Failed to get push notification token: " + error.LocalizedDescription);
            }
            else
            {
                Debug.LogError("Got push notification token");
            }
        });

        ICloudNotifications.SetRemoteNotificationHandler((p) => {
            Debug.Log("remote notification handler called");
        });

        database = CKContainer.DefaultContainer().PrivateCloudDatabase;

        // You only need to register a subscription ONCE
        // So check that a subscription exists before trying to add one
        database.FetchAllSubscriptionsWithCompletionHandler(OnSubscriptionsFetched);

        ICloudNotifications.SetRemoteNotificationHandler(OnQueryNotification);

        yield break;
    }
    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);
    }
    private void Run()
    {
        Debug.Log("Example 3 - Querying");
        database = CKContainer.DefaultContainer().PrivateCloudDatabase;

        // We need a bunch of records to search through
        names = new string[] {
            "Alice",
            "Bob",
            "Charles",
            "Danni",
            "Exavier"
        };

        // Make an array of CKRecords and set the name field to each of the
        // names in the array above...
        //
        recordsToSearch = names.Select(name => {
            var record = new CKRecord("Person");
            record.SetString(name, "name");
            return(record);
        }).ToArray();

        // CloudKit uses a CKModifyRecrodsOperation for both saving and deleting
        // (which is sorta wierd). The first parameter is records to save, the
        // second is record id's to delete
        //
        Debug.Log("Creating records");
        CKModifyRecordsOperation op = new CKModifyRecordsOperation(
            recordsToSearch,
            null
            );

        // Important to set quality of service to UserInitiated or cloudkit
        // may run your query a LONG time from now. Like minutes from now
        // (seriously). The default value of NSQualityOfServiceUtility is insane
        // You can read more about QoS here:
        // https://developer.apple.com/library/archive/documentation/Performance/Conceptual/EnergyGuide-iOS/PrioritizeWorkWithQoS.html
        op.Configuration.QualityOfService = NSQualityOfService.UserInitiated;

        // The modify records completion block is a callback function that's
        // invoked when the operation is complete
        op.ModifyRecordsCompletionBlock = OnRecordsSaved;

        database.AddOperation(op);

        var op2 = new CKFetchRecordsOperation(recordsToSearch.Select(x => x.RecordID).ToArray());

        op2.FetchRecordsCompletionHandler = (dictionary, error) =>
        {
            Debug.Log("Fetch records complete");
            //foreach (var kvp in dictionary)
            //{
            //    Debug.Log(string.Format("key:{0} value:{1}", kvp.Key.RecordName, kvp.Value));
            //}
        };
        database.AddOperation(op2);
    }
    private void Run()
    {
        Debug.Log("Example 5 - Zones");

        // Apple arcade recommends using zones for different GC users
        customZone = new CKRecordZone("GameCenterUser1");
        database   = CKContainer.DefaultContainer().PrivateCloudDatabase;

        database.SaveRecordZone(customZone, OnRecordZoneCreated);
    }
    private void Run()
    {
        Debug.Log("Example1 - Hello World");

        database = CKContainer.DefaultContainer().PrivateCloudDatabase;

        var record = new CKRecord("Hello");

        record.SetString("Hello World", "Greeting");

        database.SaveRecord(record, OnRecordSaved);
    }
    private void Run()
    {
        Debug.Log("Example 2 - Basic Database Operations");

        database = CKContainer.DefaultContainer().PrivateCloudDatabase;

        record = new CKRecord("MyType");
        record.SetString("An Example", "MyField");

        Debug.Log("Saving a record");
        database.SaveRecord(record, OnRecordSaved);
    }
示例#9
0
        public async void LoadNewPostsWithRecordID(CKRecordID recordID)
        {
            // Called when AppDelegate receives a push notification
            // The post that triggered the push may not be indexed yet, so a fetch on predicate might not see it.
            // We can still fetch by recordID though
            CKDatabase publicDB = CKContainer.DefaultContainer.PublicCloudDatabase;

            try {
                CKRecord record = await publicDB.FetchRecordAsync(recordID);

                Post postThatFiredPush = new Post(record);
                postThatFiredPush.LoadImage(null, TableView.ReloadData);
                postManager.LoadNewPosts(postThatFiredPush);
            } catch (NSErrorException ex) {
                Console.WriteLine(ex.Error);
            }
        }
示例#10
0
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("Example - NSSortDescriptor");

        Debug.Log("container is: " + CKContainer.DefaultContainer().ContainerIdentifier);

        database = CKContainer.DefaultContainer().PrivateCloudDatabase;

        var n = 10;

        Debug.Log($"making {n} records");
        var records = new CKRecord[n];

        for (var i = 0; i < records.Length; i++)
        {
            records[i] = new CKRecord(recordType);
        }

        // Make some records share the same field value
        // so we can test primary/secondary sorting
        for (var i = 1; i < n; i += 2)
        {
            var field = RandomString(8);
            records[i - 1].SetString(field, primaryFieldKey);
            records[i].SetString(field, primaryFieldKey);
        }

        for (var i = 0; i < n; i++)
        {
            var field = RandomString(4);
            Debug.Log(field);
            records[i].SetString(field, secondaryFieldKey);
        }

        Debug.Log("Saving records");
        var op = new CKModifyRecordsOperation(records, null);

        op.Configuration.QualityOfService = NSQualityOfService.UserInitiated;
        op.ModifyRecordsCompletionBlock   = OnRecordsSaved;
        database.AddOperation(op);
    }
示例#11
0
		public CloudManager ()
		{
			container = CKContainer.DefaultContainer;
			privateDatabase = container.PrivateCloudDatabase;
		}
示例#12
0
 public CloudManager()
 {
     container      = CKContainer.DefaultContainer;
     publicDatabase = container.PublicCloudDatabase;
 }
		public CloudManager ()
		{
			container = CKContainer.DefaultContainer;
			publicDatabase = container.PublicCloudDatabase;
		}
示例#14
0
 public CloudManager()
 {
     container       = CKContainer.DefaultContainer;
     privateDatabase = container.PrivateCloudDatabase;
 }