OGeek|极客世界-中国程序员成长平台

标题: ios - CKQueryOperation 中的 RequestRateLimited [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 06:37
标题: ios - CKQueryOperation 中的 RequestRateLimited

如果 CKQueryOperation 返回 RequestRateLimited 错误,应该将相同的 queryOperation 添加到 publicDatabase,还是应该根据收到的游标创建新的 queryOperation?如果发生 RequestRateLimited 错误,客户端是否会收到光标?


@farktronix:

我是否很好地实现了它,因为我收到了一个错误(在模拟器中,在糟糕的互联网条件下)

-[NSOperationQueue addOperation:]: operation is finished and cannot be enqueued

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), {

    // ..other things

    let qo = CKQueryOperation(query: query)
    let qcb: (CKQueryCursor!, NSError!) -> () = {cursor, error in

        if error == nil {

            //.. some code

        } else {

            if error.code == CKErrorCode.RequestRateLimited.rawValue {

                let retryAfter = error.userInfo![CKErrorRetryAfterKey] as! NSNumber

                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(retryAfter.doubleValue * Double(NSEC_PER_SEC))), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {

                    publicDatabase.addOperation(qo) // <- HERE is it ok? I get an error
                })
            } else {

                // .. some other code
            }
        }
    }

    qo.queryCompletionBlock = qcb
    publicDatabase.addOperation(qo)

    // .. other things ..
})



Best Answer-推荐答案


如果您收到 CKErrorRequestRateLimited 错误,那么您不应该收到新的查询游标。

每当您收到速率限制错误时,您可以在 CKErrorRetryAfterKey 键下的 userInfo 字典中指定的时间过去后重试相同的操作。

关于ios - CKQueryOperation 中的 RequestRateLimited,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29836127/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4