daniel
daniel

Reputation: 966

Why can't I query CloudKit from Xcode or CloudKit Dashboard?

When I try to query CloudKit from CloudKit Dashboard, I get an error that says:

There was a problem querying the “Entry” type.

no auth method found

When I try to query the same records from code in Xcode, I get the error message from the error object in my queryCompletionBlock property of my query operation:

The operation couldn’t be completed. (CKErrorDomain error 4.)

Where do I find what error 4 means?

Here is the code that printed the error message in debug window:

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)

Upvotes: 0

Views: 230

Answers (1)

daniel
daniel

Reputation: 966

It started working and I didn't do anything to fix it.

Upvotes: 1

Related Questions