[英]CKQueryOperation error: This operation has been rate limited
Client received error 1298: This operation has been rate limited
error from CloudKit when downloading records with CKQueryOperation
, only once, during Apple review. 客户端收到error 1298: This operation has been rate limited
在Apple审核期间,当使用CKQueryOperation
下载记录时, error 1298: This operation has been rate limited
CloudKit的error 1298: This operation has been rate limited
错误。 How can I fix this issue? 我该如何解决这个问题?
Here is to code, nothing special: 这是代码,没什么特别的:
let query = CKQuery(recordType: "Movie", predicate: NSPredicate(format: "creationDate > %@", d!))
let qo = CKQueryOperation(query: query)
let fb: (CKRecord!) -> () = {record in
temporaryContext.performBlockAndWait({
let fr = NSFetchRequest(entityName: "Movie")
fr.predicate = NSPredicate(format: "recordName = %@", record.recordID.recordName)
let a = temporaryContext.executeFetchRequest(fr, error: nil) as! [Movie]
if a.count == 0 {
let m = NSEntityDescription.insertNewObjectForEntityForName("Movie", inManagedObjectContext: temporaryContext) as! Movie
m.title = record.valueForKey("title") as! String
m.image = (record.valueForKey("image") as! CKAsset).fileURL.description
m.imageSize = Int32(record.valueForKey("imageSize") as! Int)
m.recordName = record.recordID.recordName
}
})
}
let c: ()->() = {
temporaryContext.performBlockAndWait({
let success = temporaryContext.save(nil)
})
Utility.managedObjectContext().performBlockAndWait({
let success = Utility.managedObjectContext().save(nil)
})
NSUserDefaults.standardUserDefaults().setBool(true, forKey: "moviesDownloaded")
NSUserDefaults.standardUserDefaults().synchronize()
dispatch_semaphore_signal(self.sema)
}
let cb: (CKQueryCursor!, NSError!) -> () = {cursor, error in
if error == nil {
if cursor != nil {
let qo2 = Utility.qo(cursor, recordFetchedBlock: fb, completion: c)
publicDatabase.addOperation(qo2)
} else {
c()
}
} else {
Utility.log("error 1298: \(error.localizedDescription)")
dispatch_sync(dispatch_get_main_queue(), {
self.status.backgroundColor = UIColor.orangeColor()
})
NSThread.sleepForTimeInterval(0.5)
dispatch_semaphore_signal(self.sema)
}
}
qo.recordFetchedBlock = fb
qo.queryCompletionBlock = cb
publicDatabase.addOperation(qo)
dispatch_semaphore_wait(self.sema, DISPATCH_TIME_FOREVER)
I try to put this whole code into a loop like: 我尝试将整个代码放入一个循环中:
for i in 1 ... 2 {
var rateLimited = false
...
if error == nil {
} else {
NSThread.sleepForTimeInterval(3)
rateLimited = true
}
...
if !rateLimited {
break
}
}
Do you think it will work? 你觉得它会起作用吗?
If you get CKErrorRequestRateLimited
the error will have a CKErrorRetryAfterKey
key in the error's userInfo
dictionary. 如果你得到CKErrorRequestRateLimited
那么错误将在错误的userInfo
字典中有一个CKErrorRetryAfterKey
键。 You should wait at least that amount of time before retrying your operation. 在重试操作之前,您应至少等待一段时间。
Waiting with a sleep is a bad idea because it can cause unexpected hangs in your application, especially if that code runs on your main thread. 等待睡眠是一个坏主意,因为它可能会导致应用程序意外挂起,特别是如果该代码在您的主线程上运行。 Use dispatch_after
or a NSTimer
to re-send your operation. 使用dispatch_after
或NSTimer
重新发送您的操作。
如果您未登录到iCloud帐户,也会收到此错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.