为什么我不能从Xcode或CloudKit Dashboard查询CloudKit?

时间:2019-02-05 10:03:35

标签: ios xcode cloudkit ckqueryoperation

当我尝试从CloudKit仪表板查询CloudKit时,出现错误消息:

  

查询“ Entry”类型时出现问题。

     

未找到身份验证方法

当我尝试从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)

1 个答案:

答案 0 :(得分:0)

它开始工作,我没有做任何修复。