ios – CloudKit CKModifyRecordsOperation给了我一个“保护数据不匹配”

前端之家收集整理的这篇文章主要介绍了ios – CloudKit CKModifyRecordsOperation给了我一个“保护数据不匹配”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用CloudKit上传一些记录更改.我正在使用CKModifyRecordsOperation来批量上传设备上已更改的记录.记录都在自定义区域中

由于某种原因,操作不断回来,并告诉我“”保护数据不匹配“

这是代码

- (void)updloadLocalChangesWithCompletionBlock:(void (^)(NSError *error))completionBlock
{
   // Initialize the data
   NSArray *localChanges = self.localChanges;
   NSArray *localDeletions = self.localDeletions;

   // Initialize the database and modify records operation
   CKDatabase *database = [CKContainer defaultContainer].privateCloudDatabase;
   CKModifyRecordsOperation *modifyRecordsOperation = [[CKModifyRecordsOperation alloc] initWithRecordsToSave:localChanges recordIDsToDelete:localDeletions];
   modifyRecordsOperation.savePolicy = CKRecordSaveAllKeys;

   NSLog(@"CLOUDKIT Changes Uploading: %d",localChanges.count);

   // Add the completion block
   modifyRecordsOperation.modifyRecordsCompletionBlock = ^(NSArray *savedRecords,NSArray *deletedRecordIDs,NSError *error) {
       if (error) {
           NSLog(@"[%@] Error pushing local data: %@",self.class,error);
       }

       [self.localChanges removeObjectsInArray:savedRecords];
       [self.localDeletions removeObjectsInArray:deletedRecordIDs];

       completionBlock(error);
   };

   // Start the operation
   [database addOperation:modifyRecordsOperation];
}

这是它给我的错误

[CloudKitSyncManager] Error Uploading Changes: <CKError 0x156654a0: "Partial Failure" (2/1011); "Failed to modify some records"; partial errors: {
    default-00001:(ZoneName:UserRecordID) = <CKError 0x1550b5a0: "Server Record Changed" (14/2037); "Error saving record <CKRecordID: 0x18080430; default-00001:(ZoneName:UserRecordID)> to server: Protection data didn't match">
}>

解决方法

你的self.localChanges数组究竟是什么? CKRecord我假设,但您是根据从CloudKit下载的相同CKRecord对象上传修改记录?

当我尝试使用我的本地更改上传新分配的CKRecord并期望它覆盖服务器的副本时,我有一个类似的(虽然不是确切的)错误消息.我通过下载我的项目的远程副本,将更新应用于CloudKit提供给我的CKRecord实例,然后上传它来修复它.

原文链接:https://www.f2er.com/iOS/334916.html

猜你在找的iOS相关文章