如何使用CloudKit保存多个CKRecords

时间:2018-04-28 11:53:08

标签: ios objective-c database synchronization cloudkit

CKDatabase类只有一种方法可以将记录保存到云端。 有没有其他方法可以将多个记录保存到云端?

CKRecordID *artworkRecordID = [[CKRecordID alloc] initWithRecordName:@"116"];
CKRecord *artworkRecord = [[CKRecord alloc] initWithRecordType:@"Artwork" recordID:artworkRecordID];
artworkRecord[@"title" ] = @"MacKerricher State Park";
artworkRecord[@"artist"] = @"Mei Chen";
artworkRecord[@"address"] = @"Shenzhen";

CKContainer *myContainer = [CKContainer defaultContainer];
CKDatabase *privateDatabase = myContainer.privateCloudDatabase;
[privateDatabase saveRecord:artworkRecord completionHandler:^(CKRecord * _Nullable record, NSError * _Nullable error) {
    dispatch_sync_on_main_queue(^{
        if (error) {
            self.titleLabel.text = @"Error";
            self.subTitleLabel.text = error.description;
        } else {
            self.titleLabel.text = @"Successfully";
        }
    });
}];

0 个答案:

没有答案