来自私有区域的CKQuery仅返回CloudKit中的前100个CKRecords [英] CKQuery from private zone returns only first 100 CKRecords from in CloudKit

查看:161
本文介绍了来自私有区域的CKQuery仅返回CloudKit中的前100个CKRecords的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Cloudkit 私人默认区域的查询结果是否有任何限制?我不知道为什么我只使用以下查询收到前100条记录:

Is there any limit to the result of a query to Cloudkit private default zone? I have no clue why I only receive first 100 records with the following query:

let p = NSPredicate(format: "(type == 'entered') AND (timestamp >= %@) AND (timestamp <= %@)", from, to)
let q = CKQuery(recordType: self.beaconRecordType, predicate: p)
q.sortDescriptors = [NSSortDescriptor(key: "timestamp", ascending: true)]
self.privateDatabase?.performQuery(q, inZoneWithID: nil, completionHandler: { results, error in

    //count = 100
    println(results.count)

}






好的。正如Edwin在答案中提到的,解决方案是使用CKQueryOperation获取初始数据块,然后使用completionBlock中的cursor来触发另一个以下是一个例子:


Okay. As Edwin mention in the answer, the solution is to use CKQueryOperation to fetch the initial block of data then use the "cursor" in completionBlock to fire another operation. Here is an example:

更新

func fetchBeacons(from:NSDate, to:NSDate) {

    let p = NSPredicate(value: true)
    let q = CKQuery(recordType: self.beaconRecordType, predicate: p)

    let queryOperation = CKQueryOperation(query: q)

    queryOperation.recordFetchedBlock = fetchedARecord

    queryOperation.queryCompletionBlock = { [weak self] (cursor : CKQueryCursor!, error : NSError!) in

        if cursor != nil {
            println("there is more data to fetch")
            let newOperation = CKQueryOperation(cursor: cursor)
            newOperation.recordFetchedBlock = self!.fetchedARecord
            newOperation.queryCompletionBlock = queryOperation.queryCompletionBlock
            self!.privateDatabase?.addOperation(newOperation)
        }

    }

    privateDatabase?.addOperation(queryOperation)
}

var i = 0
func fetchedARecord (record: CKRecord!) {
    println("\(NSDate().timeIntervalSinceReferenceDate*1000) \(++i)")
}


推荐答案

100是t他是标准查询的默认限制。这个数额不固定。它可能会根据iCloud的总负载而有所不同。如果你想影响那个数量,那么你需要使用CKQueryOperation并像这样设置resultsLimit:
operation.resultsLimit = CKQueryOperationMaximumResults;
CKQueryOperationMaximumResults是默认值,并将其限制为100(大部分时间)。不要将该值设置得太高。如果您想要更多记录,请使用queryCompletionBlock的光标继续阅读更多记录。

100 is the default limit for standard queries. That amount is not fixed. It can vary depending on the total iCloud load. If you want to influence that amount, then you need to use CKQueryOperation and set the resultsLimit like this: operation.resultsLimit = CKQueryOperationMaximumResults; That CKQueryOperationMaximumResults is the default and will limit it to 100 (most of the time). Don't set that value too high. If you want more records, then use the cursor of the queryCompletionBlock to continue reading more records.

这篇关于来自私有区域的CKQuery仅返回CloudKit中的前100个CKRecords的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆