I am downloading a file using Alamofire download with progress but i have no idea how to pause / resume / cancel the specific request.
@IBAction func downloadBtn
Keep a reference to the request created in downloadBtnTapped
with a property, and call cancel
on that property in pauseBtnTapped
.
var request: Alamofire.Request?
@IBAction func downloadBtnTapped() {
self.request = Alamofire.download(.GET, "http://httpbin.org/stream/100", destination: destination)
}
@IBAction func pauseBtnTapped(sender : UIButton) {
self.request?.cancel()
}
request.cancel()
will cancel the download progress. If you want to pause and continue, you can use:
var request: Alamofire.Request?
@IBAction func downloadBtnTapped() {
self.request = Alamofire.download(.GET, "http://yourdownloadlink.com", destination: destination)
}
@IBAction func pauseBtnTapped(sender : UIButton) {
self.request?.suspend()
}
@IBAction func continueBtnTapped(sender : UIButton) {
self.request?.resume()
}
@IBAction func cancelBtnTapped(sender : UIButton) {
self.request?.cancel()
}