加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – 在CloudKit中保存修改后的数据

发布时间:2020-12-15 01:45:00 所属栏目:百科 来源:网络整理
导读:我一直在测试CloudKit,因为我希望在发布iOS8时使用它来发布应用程序.使用以下代码保存数据似乎很简单: CKRecordID * recordID = [[CKRecordID alloc] initWithRecordName:@"basicRecord"];CKRecord * record = [[CKRecord alloc] initWithRecordType:@"basi
我一直在测试CloudKit,因为我希望在发布iOS8时使用它来发布应用程序.使用以下代码保存数据似乎很简单:

CKRecordID * recordID = [[CKRecordID alloc] initWithRecordName:@"basicRecord"];
CKRecord * record = [[CKRecord alloc] initWithRecordType:@"basicRecordType" recordID:recordID];
[record setValue:@"defaultValue" forKey:@"defaultKey"];
CKDatabase *database = [[CKContainer defaultContainer] publicCloudDatabase];
[database saveRecord:record completionHandler:^(CKRecord *record,NSError *error) {

    if (error) {
        NSLog(@"Error: %@",error);
    } else {
        NSLog(@"Record Saved!");
    }
}];

我没有收到任何错误.但是,如果我再次尝试运行代码,可能是因为我已将记录值更改为

[record setValue:@"newValue" forKey:@"defaultKey"];

我收到一个错误提出问题,我如何保存修改过的数据.毕竟,这是将事物保存到云端的基本部分.错误如下,任何帮助将不胜感激,请不要犹豫,要求进一步的信息.

Error: <CKError 0x17024afb0: "Server Record Changed" (14/2017); "Error saving record <CKRecordID: 0x144684a80; basicRecord:(_defaultZone:__defaultOwner__)> to server: (null)"; uuid = 182C497F-966C-418A-9E6A-5563BA6CC6CD; container ID = "iCloud.com.yourcompany.CloudKit">

解决方法

此错误可能是因为saveRecord:仅适用于比服务器上的版本更新的新记录或记录:

This method saves the record only if it has never been saved before or if it is newer than the version on the server. You cannot use this method to overwrite newer versions of a record on the server. 07000

修改现有记录(或记录集)的推荐方法是使用带有所需savePolicy的CKModifyRecordsOperation来处理冲突:

After modifying the fields of a record,use this type of operation object to save those changes to a database. (…) When saving records,the value in the savePolicy property determines how to proceed when conflicts are detected on the server. 07001

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读