当我使用CKModifyRecordsOperation
将多个表的记录保存到私有云数据库的默认区域时,它总是返回以下错误,但表“X”除外:
将记录保存到服务器时出错:将记录从“X”类型更新为“Y”的尝试无效
error.userInfo
细节:
{
CKErrorDescription = "将记录 CKRecordID: 0x7fd7a3d4c0c0; 1:(_defaultZone: defaultOwner ) 保存到服务器时出错:将记录从'X'类型更新为'Y'的尝试无效";
ContainerID = "iCloud.com...";
NSDebugDescription = "CKInternalErrorDomain: 2006";
NSLocalizedDescription = "将记录保存到服务器时出错:将记录从'X'类型更新为'Y'的尝试无效";
NSUnderlyingError = "CKError 0x7fa0d250c4e0: \"Invalid Arguments\" (2006); 服务器消息 = \"从类型 'X' 到 'Y' 更新记录的尝试无效\"; uuid = E2E...D1E; 容器 ID = \ "iCloud.com...\"";
RequestUUID = "E2E...
错误键 = ck1rosofi;
}
相关代码片段:
- (void)sync
{
...
NSMutableArray * operations;
for (NSString *tableName in @[@"X", @"Y"]) {
CKModifyRecordsOperation * operation = [self _modifyRecordsOperationWithTableName:tableName];
if (operation) {
if (operations) [operations addObject:operation];
else operations = [NSMutableArray arrayWithObject:operation];
}
}
if (operations) {
[operationQueue addOperations:operations waitUntilFinished:NO];
}
}
- (CKModifyRecordsOperation *)_modifyRecordsOperationWithTableName:(NSString *)tableName
{
...
NSMutableArray * recordsToSave = [NSMutableArray array];
for (KYModel <KYModel_iCloudProtocol> *instance in unsyncedInstances) {
CKRecordID * objectID = [[CKRecordID alloc] initWithRecordName:@(instance.id).stringValue];
CKRecord * cloudRecord = [[CKRecord alloc] initWithRecordType:tableName recordID:objectID];
... setup record detail
[recordsToSave addObject:record];
}
CKModifyRecordsOperation * operation = [[CKModifyRecordsOperation alloc] initWithRecordsToSave:recordsToSave recordIDsToDelete:nil];
operation.database = [[CKContainer defaultContainer] privateCloudDatabase];
operation.savePolicy = CKRecordSaveAllKeys;
operation.qualityOfService = NSQualityOfServiceUserInteractive;
operation.atomic = NO;
operation.perRecordProgressBlock = ...;
operation.perRecordCompletionBlock = ^(CKRecord *record, NSError *error) {
if (error) {
// got error here
}
...
};
operation.modifyRecordsCompletionBlock = ...;
return operation;
}