我在启动应用时使用CloudKit下载文件。我有一个CKQuery,可以找到尚未下载的所有文件。当只有一个或两个要下载时,它工作正常,但是当有大量数据时,它会因错误而失败:
\"服务器拒绝请求\" (2000分之15);服务器消息= \"内部服务器错误\&#34 ;;
这发生在设备或模拟器上。
相关代码
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
}
}
EDIT
我已更新我的代码以使用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)
}
但仍然收到同样的错误。
答案 0 :(得分:4)
仔细检查downloadedTitles
是否为空数组。如果在这样的查询中发送空数组,服务器将返回此错误。
这是来自服务器的错误 - 我已经提交了一个错误,以便在这种情况下返回更好的错误消息(或根本没有结果)。
答案 1 :(得分:1)
嗯,这可能实际上是内部错误。我也遇到过CloudKit的错误,并且在我的Apple Developer论坛报告后修复了。试试那里,苹果公司的开发人员可能会对你的问题做些什么。