Wil*_* T. 10 ios swift cloudkit ckqueryoperation
我想从公共数据库中下载大约500个"访问"记录.CloudKit一次只能为您提供100条记录,因此我只需使用下面的CKQueryCursor来获取我想要的所有记录.
func fetchVisits(_ cursor: CKQueryCursor? = nil) {
print("fetchVisits \(cursor)")
var operation: CKQueryOperation!
if let cursor = cursor {
operation = CKQueryOperation(cursor: cursor)
} else {
let query = CKQuery(recordType: "Visit", predicate: NSPredicate(format: "Client IN %@ AND ANY Students IN %@", visitClients, visitStudents))
operation = CKQueryOperation(query: query)
}
operation.recordFetchedBlock = {
(record) in
totalVisits.append(record)
}
operation.queryCompletionBlock = {
(cursor, error) in
if let error = error {
//handle error
} else if let cursor = cursor {
self.fetchVisits(cursor)
} else {
//all done!
}
}
CKContainer.default().publicCloudDatabase.add(operation)
}
Run Code Online (Sandbox Code Playgroud)
我把这个函数称为:
fetchVisits()
Run Code Online (Sandbox Code Playgroud)
这很好,它获得了我需要的所有访问.控制台日志
fetchVisits nil
fetchVisits Optional(<CKQueryCursor: 0x174228140; id=4bb7887c326fc719, zone=(null)>)
fetchVisits Optional(<CKQueryCursor: 0x17422a320; id=f67fb25669486da9, zone=(null)>)
fetchVisits Optional(<CKQueryCursor: 0x174228380; id=7e87eb8b7cfe1a74, zone=(null)>)
fetchVisits Optional(<CKQueryCursor: 0x17422cc80; id=e77e47ef2b29c8a4, zone=(null)>)
Run Code Online (Sandbox Code Playgroud)
但问题是现在我想按下按钮时刷新,现在它给了我这个错误:
"服务不可用"(6/2022); "请求失败,http状态代码为503"; 30.0秒后重试
这是非常自我解释的,我想我通过请求一个可怜的500条记录来压倒服务器?所以我等待30秒再次调用该函数,现在我收到此错误.
"限制超过"(27/2023); server message ="查询过滤器超出了值的限制:容器为250
出于某种原因,我无法再次运行该功能.如果我重新启动应用程序它再次正常工作,但只是第一次.此问题似乎特定于任何返回CKQueryCursor的表.我有其他的表,我打的少于100条记录(所以光标是零)我可以多次拉这些没有任何问题.
好的,所以我以前见过这个,我相信问题是 CloudKit 服务器上的一个错误。根据我的经验,它与复杂的查询有关。
如果您尝试将谓词更改为:
NSPredicate(value: true)
Run Code Online (Sandbox Code Playgroud)
或者甚至通过删除任何部分来简化您现有的部分,这可能足以修复它。
| 归档时间: |
|
| 查看次数: |
325 次 |
| 最近记录: |