【发布时间】:2015-09-03 23:49:15
【问题描述】:
我正在尝试取消查询并在没有连接时为用户设置通知。有没有比我发现的更好的方法?在警报发生之前,查询仍会运行大约 15 秒以上。
let query = Item.query()
query!.findObjectsInBackgroundWithBlock { (objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
for object in objects! {
self.items.append(object as! Item)
if self.items.count == 35 {
break
}
}
} else if error!.code == 100 {
query?.cancel()
print("query cancelled")
let alertController = UIAlertController(title: "Oops", message: "Trouble With Network", preferredStyle: .Alert)
let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
alertController.addAction(defaultAction)
self.presentViewController(alertController, animated: true, completion: nil)
} else {
print("non network Error with query")
}
self.tableView.reloadData()
}
}
【问题讨论】:
标签: ios swift parse-platform network-programming pfquery