简体   繁体   English

如何在AlamoFire的`appWillterminate`期间取消`request.Cancel()`?

[英]How to cancel `request.Cancel()` During `appWillterminate` in AlamoFire?

I am trying to save the downloaded data in download failure case 我正在尝试在下载失败的情况下保存下载的数据

            switch response.result{
        case .success( _):
            print("success response")
            break
        case .failure( _):
            print("error")
            if let resumeData = response.resumeData{
                self.resumeData = resumeData
                Shared.dataCache.set(value: resumeData, key: self.keyResumeData)
            }
        }

When I trigger request.Cancel() using button press event its working perfectly. 当我使用按钮按下事件触发request.Cancel()它的工作正常。 But when I trigger the same function during appWillTerminate its not getting into failure case. 但是当我在appWillTerminate期间触发相同的功能时,它不会陷入故障情况。 Is there any way to save downloaded data during App Termination using Alamofire 有什么方法可以在使用Alamofire的 App终止期间保存下载的数据

I think this may work for you: 我认为这可能对您有用:

 URLSession.shared.getAllTasks(){
            tasks in
            tasks.forEach { $0.cancel() }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM