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); }
public void Can_set_and_retrieve_string_by_key() { var record = new CKRecord("record_type"); var stringKey = "string_key"; var stringValue = "string_value"; record.SetString(stringValue, stringKey); Assert.AreEqual(record.StringForKey(stringKey), stringValue); }
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); }
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)); } }