Is there any way I can for example say:
Alamofire.Manager.cancelAllRequests()
or Alamofire.Manager.sharedInstance.cancelAllRequests()
?
cnoon
's one-liner solution is great but it invalidates the NSURLSession and you need to create a new one.
Another solution would be this (iOS 7+):
session.getTasks { dataTasks, uploadTasks, downloadTasks in
dataTasks.forEach { $0.cancel() }
uploadTasks.forEach { $0.cancel() }
downloadTasks.forEach { $0.cancel() }
}
Or if you target iOS 9+ only:
session.getAllTasks { tasks in
tasks.forEach { $0.cancel() }
}