I'm using Alamofire library to make a download manager.
I'm configuring the Alamofire Manager with
HTTPMaximumConnectionsPerHost = 4
.And I'm start Downloading 5 items, then 4 items start downloading and the the 5th item is waiting in queue.
When I Pause one of the first 4th item, I'm expecting the 5th item to start downloading. This is not happening and this is my issue
This is my Code:
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")
}
}
}
And this is the method for Pause Request
func pauseDownload(thisItem item: String) {
var request : Request
for req in DownloadCenter.defaultCenter.currentDownloadsList {
if req.request?.URLString == item {
request = req
request.suspend()
break
}
}
}
This is my case:
Start Downloading 5 items, 4 are Downloading and the 5th item is waiting..