我遵循了几个关于从 CloudKit 获取问题的 CKQueryOperation 示例/叙述。我的表有大约 370 行和 8 列。我最多只能获取大约 60 行。resultsLimit 参数似乎没有帮助。我的 queryCompletionBlock 没有执行。有时我获取 5 行,其他时间 30+ 来自云的响应现在很快所有行这一定是一些新手代码错误!
func getData() {
let predicate = NSPredicate(value: true)
let query = CKQuery(recordType: RemoteFunctions.RemoteRecords.booksDB, predicate: predicate)
let cloudContainer = CKContainer.default()
let privateDatabase = cloudContainer.privateCloudDatabase
let operation = CKQueryOperation(query: query)
operation.queuePriority = .veryHigh
operation.resultsLimit = 20
operation.recordFetchedBlock = { (record: CKRecord) in
self.allRecords.append(record)
print(record)
}
operation.queryCompletionBlock = {[weak self] (cursor: CKQueryCursor?, error: NSError?) in
// There is another batch of records to be fetched
print("completion block called with \(String(describing: cursor))")
if let cursor = cursor {
let newOperation = CKQueryOperation(cursor: cursor)
newOperation.recordFetchedBlock = operation.recordFetchedBlock
newOperation.queryCompletionBlock = operation.queryCompletionBlock
newOperation.resultsLimit = 10
privateDatabase.add(newOperation)
print("more records")
}
// There was an error
else if let error = error {
print("Error:", error)
}
// No error and no cursor means the operation was successful
else {
print("Finished with records:")
}
} as? (CKQueryCursor?, Error?) -> Void
// privateDatabase.add(操作)
}