我正在尝试构建一个应用程序,使用大型中央调度在后台下载某些特定图像。但是,即使我使用全局队列和调度优先级后台来获取不同的线程并下载图像,它也会阻塞主线程。所有这些都在一个类DownloadRequestViewController中。在这个类中,我从alertcontroller动作实例化代码。 这是:
controller = UIAlertController(title: "Seçenekler", message: "Ne yapmak İstersiniz?", preferredStyle: .ActionSheet)
let actionDownload = UIAlertAction(title: "Bölümü İndir", style: UIAlertActionStyle.Default, handler: {(paramAction : UIAlertAction!) in
var mbProHud : MBProgressHUD!
var viewToDisplay : UIWindow = UIApplication.sharedApplication().windows.last as! UIWindow
mbProHud = MBProgressHUD.showHUDAddedTo(viewToDisplay, animated: true)
mbProHud.customView = UIImageView(image: UIImage(named: "37x-Checkmark.png"))
mbProHud.mode = MBProgressHUDMode.CustomView
mbProHud.dimBackground = true
mbProHud.labelText = "İndirme Başlatıldı!"
mbProHud.hide(true, afterDelay: 2)
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), {
var selectedChapters : [String] = [self.currentChapter]
var mangaNameArray = [self.obtainedManga.name]
let notification = NSNotification(name: "downloadListNotification", object: self, userInfo: ["downloadList" : selectedChapters, "mangaName" : mangaNameArray])
self.downloadChapter(notification)
//NSNotificationCenter.defaultCenter().postNotification(notification)
})
})
controller!.addAction(actionDownload)
以下是下载章节方法的签名:
func downloadChapter(notification : NSNotification){}
我不认为下载章节中的内容会很重要。 请各位帮忙,谢谢......