CKRecord设置父错误4097

时间:2016-11-13 06:23:39

标签: ios swift cloudkit

我正在尝试在CKRecord上设置父级。基本上,提醒是列表的孩子。该列表已存在于服务器上。

let record = CKRecord(recordType: "Reminder", recordID: recordID)
let listID = CKRecordID(recordName: listName, zoneID: listZoneID)
record["title"] = "Test TODO"
record.setParent(listID)
let modifyRecordsOp = CKModifyRecordsOperation(recordsToSave:[record], recordsToDelete:nil)
modifyRecordsOp.modifyRecordsCompletionBlock = { (_, _, error) in
    guard error == nil else {
         print(error)
         return
    }
}

每次我这样做,都会收到以下错误: [LogFacilityCK]操作28174DD7CAF85542出现连接错误:错误域= NSCocoaErrorDomain代码= 4097“连接到名为com.apple.cloudd的服务”UserInfo = {NSDebugDescription =连接到名为com.apple.cloudd的服务}

如果删除setParent行,则会在服务器上成功创建记录。我做错了吗?

1 个答案:

答案 0 :(得分:1)

可能是因为listID记录尚未保存到云端,因此云无法将listID设置为record的父级。尝试保存两个新创建的记录:

let modifyRecordsOp = CKModifyRecordsOperation(recordsToSave:[record, listID], recordsToDelete:nil)