当我尝试从 CloudKit 仪表板查询 CloudKit 时,我收到一条错误消息:
查询“条目”类型时出现问题。
未找到身份验证方法
当我尝试从 Xcode 中的代码查询相同的记录时,我从查询操作的 queryCompletionBlock 属性中的错误对象中收到错误消息:
操作无法完成。(CKErrorDomain 错误 4。)
我在哪里可以找到错误 4 的含义?
这是在调试窗口中打印错误消息的代码:
let predicate = NSPredicate(value: true)
let query = CKQuery(recordType: DatabaseNameStrings.recordTypeEntry, predicate: predicate) // DatabaseNameStrings.recordTypeEntry = "Entry"
let sortDescriptor = NSSortDescriptor(key: DatabaseNameStrings.recordFieldKeyCreationDate, ascending: true)
query.sortDescriptors = [sortDescriptor]
let queryOperation = CKQueryOperation(query: query)
queryOperation.database = container.privateCloudDatabase
queryOperation.desiredKeys = [DatabaseNameStrings.fieldNameText] // DatabaseNameStrings.fieldNameText = "text"
queryOperation.recordFetchedBlock = {
(record: CKRecord) in
let entry = Entry(ckRecord: record)
self.entries.append(entry)
}
queryOperation.queryCompletionBlock = {
(cursor: CKQueryOperation.Cursor?, error: Error?) in
if let error = error {
print(error.localizedDescription) // The operation couldn’t be completed. (CKErrorDomain error 4.)
} else {
DispatchQueue.main.async {
self.tableView.reloadData()
}
if let cursor = cursor {
let innerQueryOperation = CKQueryOperation(cursor: cursor)
innerQueryOperation.desiredKeys = queryOperation.desiredKeys
innerQueryOperation.recordFetchedBlock = queryOperation.recordFetchedBlock
innerQueryOperation.queryCompletionBlock = queryOperation.queryCompletionBlock
queryOperationQueue.addOperation(queryOperation)
} else {
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
}
}
queryOperationQueue.addOperation(queryOperation)