[英]Why will my CKQueryOperation only return a Cursor if the results limit is less than 1000?
CloudKit has about 2000 records that I am attempting to download. CloudKit有大约2000条我试图下载的记录。 I cannot get all of them to download, I looked at CloudKit CKQueryOperation doesn't get all records to get more than 100 results. 我无法让他们全部下载,我看着CloudKit CKQueryOperation并没有获得所有记录以获得超过100个结果。 Now I can get upto 999 to download, but if I set the results limit to 1000 or more it will fail randomly between 80-500. 现在我可以下载到999,但如果我将结果限制设置为1000或更高,它将在80-500之间随机失败。 Will I need to split these entries into different record types? 我是否需要将这些条目拆分为不同的记录类型?
private func checkForCloudData() {
let query = CKQuery(recordType: "myRecordType", predicate: .init(value: true))
let op = CKQueryOperation(query: query)
op.qualityOfService = .userInitiated
op.queuePriority = .veryHigh
op.resultsLimit = 999
op.recordFetchedBlock = { record in
// fetched record
}
op.queryCompletionBlock = { cursor, err in
if cursor != nil {
print(cursor!)
self.performOperation(withOperation: CKQueryOperation(cursor: cursor!))
}
if err == nil {
// handle complete download
} else {
if (err as! CKError).code == .limitExceeded {
if cursor != nil {
self.performOperation(withOperation: CKQueryOperation(cursor: cursor!))
return
}
let newOperation = CKQueryOperation(query: query)
newOperation.resultsLimit = op.resultsLimit
newOperation.queuePriority = .veryHigh
newOperation.qualityOfService = .userInitiated
newOperation.recordFetchedBlock = op.recordFetchedBlock
newOperation.queryCompletionBlock = op.queryCompletionBlock
self.performOperation(withOperation: newOperation)
}
}
}
self.performOperation(withOperation: op)
}
private func performOperation(withOperation operation: CKQueryOperation) {
publicDB.add(operation)
}
I believe that 400 is the the limit for a single operation, so you need to use cursor to get more records, and keep on doing that while returned cursor is not nil
. 我相信400是单个操作的限制,因此您需要使用游标来获取更多记录,并在返回游标不nil
时继续执行此操作。
See how it is done in RxCloudKit library' RecordFetcher
- https://github.com/maxvol/RxCloudKit/blob/master/RxCloudKit/RecordFetcher.swift 看看它是如何在RxCloudKit库' RecordFetcher
- https://github.com/maxvol/RxCloudKit/blob/master/RxCloudKit/RecordFetcher.swift
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.