【发布时间】:2017-07-23 03:45:21
【问题描述】:
我会推送通知。如果数据库中没有数据,则在显示之前下载。我用Grand Central Dispatch做了一个时间间隔,但它不正确,因为例如如果用户是一个弱互联网应用程序下降。
GCD 的屏障在下载数据之前如何延迟数据的显示?
这段代码有时间间隔:
if equal == false {
let url = "https://****.**/json/post/\(data)"
self.download.getLastestNews(url)
}
let when = DispatchTime.now() + 2
DispatchQueue.main.asyncAfter(deadline: when) {
let newsCategory = self.realm.objects(News.self).filter("newsID == \(self.id)")
vc.titleText = (newsCategory.first?.newsTitle)!
vc.fullText = (newsCategory.first?.newsFullText)!
vc.imageLink = (newsCategory.first?.newsImage)!
if let tabBarController = self.window?.rootViewController {
tabBarController.present(vc, animated: true, completion: nil)
}
}
平台 iOS 9.*、iOS 3
【问题讨论】:
标签: ios swift grand-central-dispatch barrier