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);
    }
Ejemplo n.º 2
0
        public void LoadImage(string[] keys, Action updateBlock = null)
        {
            // Fetches the imageRecord this post record references in its ImageRefKey.
            // Only fetches the values associated with the keys passed in to the NSArray
            var imgRecordId = ((CKReference)PostRecord[ImageRefKey]).RecordId;
            CKFetchRecordsOperation imageOp = new CKFetchRecordsOperation(new CKRecordID[] {
                imgRecordId
            });

            imageOp.DesiredKeys = keys;
            imageOp.Completed   = (NSDictionary recordDict, NSError error) => {
                if (error != null && error.Code == (long)CKErrorCode.PartialFailure)
                {
                    CKErrorInfo info = new CKErrorInfo(error);
                    error = info[imgRecordId];
                }

                Error errorResponse = HandleError(error);
                switch (errorResponse)
                {
                case Error.Success:
                    CKRecord fetchedImageRecord = (CKRecord)recordDict[imgRecordId];
                    ImageRecord = new Image(fetchedImageRecord);
                    if (updateBlock != null)
                    {
                        updateBlock();
                    }
                    break;

                case Error.Retry:
                    Utils.Retry(() => LoadImage(keys, updateBlock), error);
                    ImageRecord = null;
                    break;

                case Error.Ignore:
                    Console.WriteLine("Error: {0}", error.Description);
                    ImageRecord = null;
                    break;

                default:
                    throw new NotImplementedException();
                }
            };
            PublicDB.AddOperation(imageOp);
        }
Ejemplo n.º 3
0
		public void LoadImage (string[] keys, Action updateBlock = null)
		{
			// Fetches the imageRecord this post record references in its ImageRefKey.
			// Only fetches the values associated with the keys passed in to the NSArray
			var imgRecordId = ((CKReference)PostRecord[ImageRefKey]).RecordId;
			CKFetchRecordsOperation imageOp = new CKFetchRecordsOperation (new CKRecordID[]{
				imgRecordId
			});
			imageOp.DesiredKeys = keys;
			imageOp.Completed = (NSDictionary recordDict, NSError error) => {
				if(error != null && error.Code == (long)CKErrorCode.PartialFailure) {
					CKErrorInfo info = new CKErrorInfo(error);
					error = info[imgRecordId];
				}

				Error errorResponse = HandleError(error);
				switch(errorResponse) {
					case Error.Success:
						CKRecord fetchedImageRecord = (CKRecord)recordDict[imgRecordId];
						ImageRecord = new Image(fetchedImageRecord);
						if(updateBlock != null)
							updateBlock();
						break;

					case Error.Retry:
						Utils.Retry(() => LoadImage(keys, updateBlock), error);
						ImageRecord = null;
						break;

					case Error.Ignore:
						Console.WriteLine ("Error: {0}", error.Description);
						ImageRecord = null;
						break;

					default:
						throw new NotImplementedException();
				}
			};
			PublicDB.AddOperation (imageOp);
		}
 public void SetUp()
 {
     TestRuntime.AssertXcodeVersion(6, 0);
     op = new CKFetchRecordsOperation(recordIDs);
 }
 public void SetUp()
 {
     TestRuntime.AssertXcodeVersion(6, 0);
     TestRuntime.AssertSystemVersion(ApplePlatform.MacOSX, 10, 10, throwIfOtherPlatform: false);
     op = new CKFetchRecordsOperation(recordIDs);
 }