I am trying to fetch my CloudKit record and then update it with new data.
I have imported CloudKit framework I have added CloudKit and key/values to my capabilities. I have put them into my entitlements. I have use Schemas to create new custom type private records and added 5 fields. I would like to know how to update these field strings in my iphone app and then get that information on my watch app and put the data in text labels.
I have tried various things but nothing seems to be working. I am working in objc. Could someone help me.
Here is some code I am trying to get to work but with little success. As a 68 yr old retired art teacher teaching myself this I am not a trained coder and need all the help I can get.
I just tried this and it runs through, but I can't see where I put in the values for the keys I have put in. Where do I put those values to modify.
Like I said I have set up a private database Pool and a CKRecordID MyPoolInfo and fields but I am totally lost. There is very little out there for people working in objective-c.
HELP
I have imported CloudKit framework I have added CloudKit and key/values to my capabilities. I have put them into my entitlements. I have use Schemas to create new custom type private records and added 5 fields. I would like to know how to update these field strings in my iphone app and then get that information on my watch app and put the data in text labels.
I have tried various things but nothing seems to be working. I am working in objc. Could someone help me.
Here is some code I am trying to get to work but with little success. As a 68 yr old retired art teacher teaching myself this I am not a trained coder and need all the help I can get.
I just tried this and it runs through, but I can't see where I put in the values for the keys I have put in. Where do I put those values to modify.
Code Block NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; // or @"yyyy-MM-dd hh:mm:ss a" if you prefer the time with AM/PM NSLog(@"%@",[dateFormatter stringFromDate:[NSDate date]]); NSString *date =[dateFormatter stringFromDate:[NSDate date]]; NSString *myPoolString = @"MyPoolInfo"; NSString *MyPoolInfoString = [myPoolString stringByAppendingString:date]; NSLog(@"MyPoolInfoString:::%@",MyPoolInfoString); CKRecordID *recordID = [[CKRecordID alloc]initWithRecordName:myPoolString]; NSLog(@"recordID:::%@", recordID); CKRecord *record = [[CKRecord alloc] initWithRecordType: @"Pool" recordID: recordID]; [[CKContainer defaultContainer].privateCloudDatabase fetchRecordWithID:recordID completionHandler:^(CKRecord *record, NSError *error) { NSArray *myFields = [NSArray arrayWithObjects:@"temperature",@"date",@"level",@"trip",@"battery",nil]; CKModifyRecordsOperation *modifyRecords= [[CKModifyRecordsOperation alloc] initWithRecordsToSave:myFields recordIDsToDelete:nil]; //[modifyRecords setValue:self.myTrip forKey:@"temperature"]; //[modifyRecords setValue:self.myDate forKey:@"date"]; modifyRecords.savePolicy=CKRecordSaveAllKeys; modifyRecords.qualityOfService=NSQualityOfServiceUserInitiated; modifyRecords.modifyRecordsCompletionBlock= ^(NSArray * savedRecords, NSArray * deletedRecordIDs, NSError * operationError){ // the completion block code here [record setObject: self.myTemp forKey: @"temperature"]; NSLog(@"savedRecords:%@",savedRecords); }; [[CKContainer defaultContainer].privateCloudDatabase addOperation:modifyRecords]; }];
Like I said I have set up a private database Pool and a CKRecordID MyPoolInfo and fields but I am totally lost. There is very little out there for people working in objective-c.
HELP