ios – 如何在Alamofire中暂停/恢复/取消我的下载请求
2019年09月06日
作者:佚名
我正在使用Alamofire下载进行文件下载,但我不知道如何暂停/恢复/取消特定的请求.
@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 }
解决方法
保留对使用属性的downloadBtnTapped中创建的请求的引用,并在pauseBtnTapped中调用该属性的cancel.
var request: Alamofire.Request? @IBAction func downloadBtnTapped() { self.request = Alamofire.download(.GET,destination: destination) } @IBAction func pauseBtnTapped(sender : UIButton) { self.request?.cancel() }
以上是来客网为你收集整理的ios – 如何在Alamofire中暂停/恢复/取消我的下载请求全部内容,希望文章能够帮你解决ios – 如何在Alamofire中暂停/恢复/取消我的下载请求所遇到的程序开发问题。
如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。