如何在Alamofire中暂停/恢复/取消我的下载请求 [英] How to pause/resume/cancel my download request in Alamofire
本文介绍了如何在Alamofire中暂停/恢复/取消我的下载请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Alamofire下载文件,但我不知道如何暂停/恢复/取消特定请求。
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 downloadBtnTapped() {
Alamofire.download(.GET, "http://httpbin.org/stream/100", destination: destination)
.progress { (bytesRead, totalBytesRead, totalBytesExpectedToRead) in
println(totalBytesRead)
}
.response { (request, response, _, error) in
println(response)
}
}
@IBAction func pauseBtnTapped(sender : UIButton) {
// i would like to pause/cancel my download request here
}
推荐答案
保留对<$ c中创建的请求的引用$ c> downloadBtnTapped 带有一个属性,并在 pauseBtnTapped
中的该属性上调用 cancel
。
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()
}
这篇关于如何在Alamofire中暂停/恢复/取消我的下载请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文