iOS Alamofire stop all requests

前端 未结 8 1591
刺人心
刺人心 2020-12-05 07:45

Is there any way I can for example say:

Alamofire.Manager.cancelAllRequests() or Alamofire.Manager.sharedInstance.cancelAllRequests()?

8条回答
  •  借酒劲吻你
    2020-12-05 08:04

    You should use the NSURLSession methods directly to accomplish this.

    Alamofire.SessionManager.default.session.invalidateAndCancel()
    

    This will call all your completion handlers with cancellation errors. If you need to be able to resume downloads, then you'll need to grab the resumeData from the request if it is available. Then use the resume data to resume the request in place when you're ready.

提交回复
热议问题