- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用大批量数据创建 CKQuery 操作时遇到问题。我的查询适用于 100 个结果,但在更多结果查询失败后,因为一个线程调度错误或其他原因(libdispatch.dylib`dispatch_group_leave:) 我迷路了……有什么想法吗?
+ (void) fetchAnswersWithRecordId:(CKRecordID *)recordId completionHandler:(CloudKitCompletionHandler)handler {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANSrecordID == %@", recordId];
CKQuery *query = [[CKQuery alloc] initWithRecordType:ckAnswers predicate:predicate];
CKQueryOperation *operation = [[CKQueryOperation alloc] initWithQuery:query];
CKQueryOperation * __weak weakSelf = operation;
operation.resultsLimit = 300;
NSMutableArray *tmp = [[NSMutableArray alloc] init];
operation.recordFetchedBlock = ^(CKRecord *record) {
[tmp addObject:record];
};
operation.queryCompletionBlock = ^(CKQueryCursor *cursor, NSError *error) {
if (!handler)
return;
NSArray *array = [NSArray arrayWithArray:tmp];
if(cursor != nil) {
CKQueryOperation *newOperation = [[CKQueryOperation alloc] initWithCursor:cursor];
newOperation.recordFetchedBlock = weakSelf.recordFetchedBlock;
newOperation.completionBlock = weakSelf.completionBlock;
[[self publicCloudDatabase] addOperation:newOperation];
} else {
NSLog(@"Results: %lu", [array count]);
dispatch_async(dispatch_get_main_queue(), ^{
handler(array, error);
});
}
};
[[self publicCloudDatabase] addOperation:operation];}
最佳答案
我认为您的问题在于 __weak 操作以及您在另一个操作中创建操作的方式。这是一个示例(快速),说明我如何做类似的事情,即获得额外的结果,但在获取而不是查询中。注意第一次使用实例变量初始化,通过GCD dispatch_aync使用半递归:
private func _fetchRecordChangesFromCloud() {
if !_fetching {
// this is the first and only time this code is called in GCD recusion
// we clean the caches we use to collect the results of the fetch
// so we can then save the record in the correct order so references can be created
_fetchedModifiedRecords = []
_fetchedDeletedRecordIDs = []
// mark fetching has started
_fetching = true
}
let operation = CKFetchRecordChangesOperation(recordZoneID: _customRecordZoneID, previousServerChangeToken: _serverChangeToken)
operation.recordChangedBlock = { (record: CKRecord?) in
if let record = record {
println("Received record to save: \(record)")
self._fetchedModifiedRecords.append(record)
}
}
operation.recordWithIDWasDeletedBlock = { (recordID: CKRecordID?) in
if let recordID = recordID {
println("Received recordID to delete: \(recordID)")
self._fetchedDeletedRecordIDs.append(recordID)
}
}
operation.fetchRecordChangesCompletionBlock = {
(serverChangeToken: CKServerChangeToken?, clientChangeToken: NSData?, error: NSError?) -> Void in
if let error = error {
println("Error in fetching record changes: \(error)")
// try again next sync
self._fetchAfterNextSuccessfullSync = true
self._fetching = false
return
}
// fetched records successfuly
println("fetched records successfuly")
if let serverChangeToken = serverChangeToken {
self._serverChangeToken = serverChangeToken
}
if operation.moreComing {
// we need to create another operation object and do it again
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
self._fetchRecordChangesFromCloud()
}
} else {
// we are finally done
// process the fetched records
self._processFetchedRecords()
// save all changes back to persistent store
self._saveBackgroundContext()
// we are done
self._fetching = false
}
}
self._privateDatabase.addOperation(operation)
}
关于objective-c - CKQueryOperation 处理大批量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30179107/
我需要获取cloudkit中的最后一条记录。这是我的代码: CKContainer *container = [CKContainer containerWithIdentifier:contain
我有一个 CKQueryOperation 处理一千条记录,因此我需要多次执行该操作。我尝试更改光标并添加如下代码中的操作: let queryOperation = CKQueryOperation
我在使用大批量数据创建 CKQuery 操作时遇到问题。我的查询适用于 100 个结果,但在更多结果查询失败后,因为一个线程调度错误或其他原因(libdispatch.dylib`dispatch_g
我在iOS 9应用程序中使用CloudKit,并且有一个CKQueryOperation可以正常工作,并且插入Mac后按预期执行。当查询未插入Mac时运行后,它不会完成。没有错误消息,我添加的 Act
我尝试在 CloudKit 数据库上使用 CKQueryOperation,而不是 performQuery。 两者都有效,但是当使用 CKQueryOperation 时,设备离线时我不会收到错误消
如果 CKQueryOperation 返回一个 RequestRateLimited 错误,是应该将相同的 queryOperation 添加到 publicDatabase,还是应该根据收到的游标
在大量搜索示例代码后设法拼凑出一个 CKFetchRecordsOperation;在这里……但我一定错过了什么。不要误会我的意思,这是一种享受……但是…… 要执行 CKFetchRecordsOpe
我的应用程序需要使用 CKDatabase 运行 CKQueryOperation。这需要并不总是可用的网络访问。 一旦我向 CKDatabase 添加了一个 CKQueryOperation,这就是
我才刚刚开始使用 CloudKit,请多多包涵。 背景信息 在 WWDC 2015 上,苹果发表了关于 CloudKit 的演讲 https://developer.apple.com/videos/
我正在尝试在我的 CloudKit 数据库上使用 CKQueryOperation,而不是 performQuery。 两者都有效,但是当使用 CKQueryOperation 时,当设备处于离线状态
是否可以在 cloudkit 中实现“批量获取”,以便我可以调用一个方法来提取下一个 X 记录?目前,根据CloudKit Batch Fetches? cloudkit 隐式处理这个问题,但我想以某
情况是这样的——我正在使用一个简单的 UITableView 来呈现来自 CloudKit publicDB 的记录。当我运行该应用程序时,查询操作返回例如返回 2 个结果(目前只有这些结果)。 我的
resultLimit 的最大值是多少?我来自 parse.com,所以我习惯于使用批量下载,当这算作一个请求调用时,可以轻松地一次提取 1000 行数据。CKQueryOperation 有哪些限制
我需要查询记录类型为“事件”的 CKRecords。当我调用 recordFetchedBlock 时,我会将这些记录添加到我的数组中。但是,recordFetchedBlock 永远不会被调用。请帮
我是使用 CloudKit 和数据库获取的新手,我已经查看了 CKDataBaseOperation 调用,所以我试图了解向数据库添加操作和在该数据库上使用“正常”函数调用之间的真正区别,如果他们两者
我将如何声明一个从 CloudKit 中检索记录的闭包,该闭包会迭代调用自身直到获取所有记录?下面的代码就是这样做的,除了我收到一条错误消息 Variable used within its own
我正在尝试使用 CloudKit 和光标从我的 iCloud 公共(public)数据库下载一批记录。无论 resultsLimit 是如何设置的,代码在前 3 次执行中工作正常,但永远不会执行第 4
CloudKit 有大约 2000 条记录我正在尝试下载。我无法全部下载,我查看了 CloudKit CKQueryOperation doesn't get all records获得超过 100
我实现了 CloudKit 抓取功能。但是我这里有一些问题。当我使用下面的代码时 let cloudContainer = CKContainer.defaultContainer()
我是一名优秀的程序员,十分优秀!