我正在使用Alamofire库制作下载管理器。
我正在配置Alamofire Manager
HTTPMaximumConnectionsPerHost = 4
。
我开始下载5个项目,然后4个项目开始下载和 第五项正在排队等候。
当我暂停第4项中的一项时,我期待第5项 开始下载。这没有发生,这是我的问题
这是我的代码:
func startDownload(thisItem url: String, folderName: String) {
let startDownloadRequest = AlamofireManager!.download(.GET, url,
destination: { temporaryURL, response in
let fileManager = NSFileManager.defaultManager()
let directoryURL = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
self.createFolderWithName(folderName)
let pathComponent = "\(folderName)/\(response.suggestedFilename!)"
return directoryURL.URLByAppendingPathComponent(pathComponent)
})
.progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
dispatch_async(dispatch_get_main_queue())
{
let progress = String(Float(totalBytesRead) / Float(totalBytesExpectedToRead))
}
}
.response { _, _, _, error in
if let error = error {
print("Failed with error: \(error)")
} else {
print("Downloaded file successfully")
}
}
}
这是暂停请求的方法
func pauseDownload(thisItem item: String) {
var request : Request
for req in DownloadCenter.defaultCenter.currentDownloadsList {
if req.request?.URLString == item {
request = req
request.suspend()
break
}
}
}