0

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.. enter image description here

After Pausing... enter image description here

Atef
  • 2,872
  • 1
  • 36
  • 32
  • Pausing the task doesn't remove it from the queue unlike a completion or a cancelation. There's still 4 active tasks in the queue. – Crazyrems Aug 09 '16 at 12:08
  • I knew that, how to cancel the active request but when downloading it again it will resume on the downloaded data not starting from the first ?? – Atef Aug 09 '16 at 12:26
  • Possible duplicate of [How to pause/resume downloads in iPhone (iOS)](http://stackoverflow.com/questions/10414201/how-to-pause-resume-downloads-in-iphone-ios) – Crazyrems Aug 09 '16 at 12:42
  • It's not duplicate question, I didn't find a question with my need.. – Atef Aug 09 '16 at 13:11
  • Maybe I shouldn't had to present this topic as a duplicate, but it should help you with your issue. – Crazyrems Aug 09 '16 at 13:16

0 Answers0