CloudKit CKModifyRecordsOperation错误

时间:2017-04-27 16:59:46

标签: ios objective-c cloudkit

我正在使用CKModifyRecordsOperation在CloudKit中批量创建大约8000条记录。但是,对于约5%的记录,我收到一个奇怪的错误:record to insert already exists。经过彻底的调查和重新测试后,我无法弄清楚为什么会这样。需要考虑的注意事项:

  1. 数据库在开始时完全为空。
  2. 我使用方法[NSUUID UUID].UUIDString在本地为每条记录创建一个recordName。在重新测试期间,我还通过创建一组recordNames并将其计数与要上载的总记录数进行比较,确认没有重复的recordNames。
  3. 我已经确认每条记录只上传一次,只需在批量上传操作中添加一个计数器,即可比较上传前的总记录数。
  4. 所有记录都已正确上传(CloudKit中的计数与上传的总记录数相比) - 因此不确定"错误"正在发生。
  5. 有关为何产生这些错误的想法吗?

    代码:

    - (void)uploadInitialRecordsToCloudKit:(NSArray *)recordsToUpload {
    
        NSArray *recordsForThisBatch = recordsToUpload;
        NSArray *remainingRecords = nil;
    
        if ([recordsToUpload count] > 350) recordsForThisBatch = [recordsToUpload subarrayWithRange:NSMakeRange(0, 350)];
        remainingRecords = [recordsToUpload subarrayWithRange:NSMakeRange([recordsForThisBatch count], [recordsToUpload count] -[recordsForThisBatch count])];
    
        CKModifyRecordsOperation *modifyRecordsOperation = [[CKModifyRecordsOperation alloc] initWithRecordsToSave:recordsForThisBatch recordIDsToDelete:nil];
        modifyRecordsOperation.modifyRecordsCompletionBlock = ^(NSArray<CKRecord *> * _Nullable savedRecords, NSArray<CKRecordID *> * _Nullable deletedRecordIDs, NSError * _Nullable operationError) {
    
            if (operationError) NSLog(@"Error during batch save to CK: %@\n\n%@", [operationError localizedDescription], operationError.userInfo);
            else NSLog(@"Batch upload to CK successful");
    
            if ([remainingRecords count] > 0) [self uploadInitialRecordsToCloudKit:remainingRecords];
    
        };
    
        [[CKContainer defaultContainer] publicCloudDatabase] addOperation:modifyRecordsOperation];
    
    }
    

1 个答案:

答案 0 :(得分:0)

这似乎是一个CloudKit问题,因为第三次测试没有任何错误。