在苹果审查期间,客户端在用error 1298: This operation has been rate limited下载记录时只从CloudKit处收到一次错误信息。我怎样才能解决这个问题?
这里是代码,没有什么特别的:
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)我试图将整个代码放入一个循环中,例如:
for i in 1 ... 2 {
var rateLimited = false
...
if error == nil {
} else {
NSThread.sleepForTimeInterval(3)
rateLimited = true
}
...
if !rateLimited {
break
}
}你觉得会成功吗?
发布于 2015-04-15 23:05:23
如果得到CKErrorRequestRateLimited,错误将在错误的userInfo字典中有一个CKErrorRetryAfterKey键。在重新尝试您的操作之前,您至少应该等待这么长的时间。
等待睡眠是个坏主意,因为它会导致应用程序中意外的挂起,特别是在主线程上运行该代码时。使用dispatch_after或NSTimer重新发送您的操作。
发布于 2015-12-04 21:00:22
如果您没有登录到您的iCloud帐户,也会收到此错误。
https://stackoverflow.com/questions/29661561
复制相似问题