CloudKit 有大约 2000 条我正在尝试下载的记录。我无法将它们全部下载,我查看了CloudKit CKQueryOperation 没有获取所有记录以获得超过 100 个结果。现在我最多可以下载 999,但如果我将结果限制设置为 1000 或更多,它将在 80-500 之间随机失败。我是否需要将这些条目拆分为不同的记录类型?
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)
}