ios – 如何在Alamofire中暂停/恢复/取消我的下载请求

我正在使用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, "http://httpbin.org/stream/100", destination: destination)
}

@IBAction func pauseBtnTapped(sender : UIButton) {
  self.request?.cancel()
}

转载注明原文:ios – 如何在Alamofire中暂停/恢复/取消我的下载请求 - 代码日志