返回大集合时 CKQuery 失败
CKQuery fails when returning large set
我正在使用 CloudKit 在应用程序启动时下载文件。我有一个 CKQuery 可以找到所有尚未下载的文件。当只有一两个下载时它工作正常,但是当有大量下载时,它会失败并显示错误:
\"Server Rejected Request\" (15/2000); server message = \"Internal server error\";
这发生在设备或模拟器上。
相关代码
let container = CKContainer(identifier: "iCloud.quaritate.Agni")
let publicDB = container.publicCloudDatabase
let privateDB = container.privateCloudDatabase
let predicate = NSPredicate(format: "NOT (%@ CONTAINS Name)", downloadedTitles)
let query = CKQuery(recordType: "List", predicate: predicate)
publicDB.performQuery(query, inZoneWithID: nil, completionHandler: {
results, error in
if error != nil{
//error getting lists
NSLog("\(error?.description)")
}else{
//got lists
}
}
编辑
我已经更新我的代码以使用 CKOperationQueue
func getNewWords(){
let predicate = NSPredicate(format: "NOT (%@ CONTAINS Name)", downloadedTitles)
let query = CKQuery(recordType: "List", predicate: predicate)
let queryOperation = CKQueryOperation(query: query)
let operationQueue = NSOperationQueue()
self.executeQueryOperation(queryOperation, onOperationQueue: operationQueue)
}
func executeQueryOperation(queryOperation: CKQueryOperation, onOperationQueue operationQueue: NSOperationQueue) {
NSLog("Executing query operation")
let container = CKContainer(identifier: "iCloud.quaritate.Agni")
let publicDB = container.publicCloudDatabase
queryOperation.database = publicDB
queryOperation.recordFetchedBlock = {(record:CKRecord) in
self.saveRecord(record)
}
queryOperation.queryCompletionBlock = {(cursor:CKQueryCursor?, error:NSError?)->Void in
guard error == nil else{
NSLog("Query error: \(error?.description)")
return
}
if let queryCursor = cursor { //there are more operations to execute
let queryCursorOperation = CKQueryOperation(cursor: queryCursor)
self.executeQueryOperation(queryCursorOperation, onOperationQueue: operationQueue)
}
}
operationQueue.addOperation(queryOperation)
}
但仍然收到相同的错误。
好吧,这实际上可能是 内部错误。 我也遇到了 CloudKit 的错误,并且在我在 Apple 开发者论坛中报告后已得到修复。试试看,Apple 的开发人员可能会解决您的问题。
仔细检查 downloadedTitles
是否为空数组。如果在这样的查询中发送空数组,服务器将 return 此错误。
这是服务器的错误错误 - 我已经提交了一个错误以获得更好的错误消息(或者根本没有结果)return在这种情况下。
我正在使用 CloudKit 在应用程序启动时下载文件。我有一个 CKQuery 可以找到所有尚未下载的文件。当只有一两个下载时它工作正常,但是当有大量下载时,它会失败并显示错误:
\"Server Rejected Request\" (15/2000); server message = \"Internal server error\";
这发生在设备或模拟器上。
相关代码
let container = CKContainer(identifier: "iCloud.quaritate.Agni")
let publicDB = container.publicCloudDatabase
let privateDB = container.privateCloudDatabase
let predicate = NSPredicate(format: "NOT (%@ CONTAINS Name)", downloadedTitles)
let query = CKQuery(recordType: "List", predicate: predicate)
publicDB.performQuery(query, inZoneWithID: nil, completionHandler: {
results, error in
if error != nil{
//error getting lists
NSLog("\(error?.description)")
}else{
//got lists
}
}
编辑
我已经更新我的代码以使用 CKOperationQueue
func getNewWords(){
let predicate = NSPredicate(format: "NOT (%@ CONTAINS Name)", downloadedTitles)
let query = CKQuery(recordType: "List", predicate: predicate)
let queryOperation = CKQueryOperation(query: query)
let operationQueue = NSOperationQueue()
self.executeQueryOperation(queryOperation, onOperationQueue: operationQueue)
}
func executeQueryOperation(queryOperation: CKQueryOperation, onOperationQueue operationQueue: NSOperationQueue) {
NSLog("Executing query operation")
let container = CKContainer(identifier: "iCloud.quaritate.Agni")
let publicDB = container.publicCloudDatabase
queryOperation.database = publicDB
queryOperation.recordFetchedBlock = {(record:CKRecord) in
self.saveRecord(record)
}
queryOperation.queryCompletionBlock = {(cursor:CKQueryCursor?, error:NSError?)->Void in
guard error == nil else{
NSLog("Query error: \(error?.description)")
return
}
if let queryCursor = cursor { //there are more operations to execute
let queryCursorOperation = CKQueryOperation(cursor: queryCursor)
self.executeQueryOperation(queryCursorOperation, onOperationQueue: operationQueue)
}
}
operationQueue.addOperation(queryOperation)
}
但仍然收到相同的错误。
好吧,这实际上可能是 内部错误。 我也遇到了 CloudKit 的错误,并且在我在 Apple 开发者论坛中报告后已得到修复。试试看,Apple 的开发人员可能会解决您的问题。
仔细检查 downloadedTitles
是否为空数组。如果在这样的查询中发送空数组,服务器将 return 此错误。
这是服务器的错误错误 - 我已经提交了一个错误以获得更好的错误消息(或者根本没有结果)return在这种情况下。