如果结果限制小于 1000,为什么我的 CKQueryOperation 只会 return 一个 Cursor?

Why will my CKQueryOperation only return a Cursor if the results limit is less than 1000?

CloudKit 我正在尝试下载大约 2000 条记录。我无法下载所有这些,我查看了 CloudKit CKQueryOperation doesn't get all records 获得了 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)
}

我认为400是单次操作的极限,所以你需要使用游标来获取更多的记录,并继续这样做,而返回的游标不是nil

在 RxCloudKit 库中查看它是如何完成的' RecordFetcher - https://github.com/maxvol/RxCloudKit/blob/master/RxCloudKit/RecordFetcher.swift