Hi,
I recently migrating my code to Swift 3 and Alamofire 4. Before I use two different code to cancel all requests :
Alamofire.manager.session.getAllTasksWithCompletionHandler { (tasks) -> Void in
tasks.forEach({ $0.cancel() })
}
or
Alamofire.manager.session.invalidateAndCancel()
But in Alamofire 4, I can't find a way to cancel all requests. Do you have an idea ?
let sessionManager = Alamofire.SessionManager.default
sessionManager.session.getTasksWithCompletionHandler { dataTasks, uploadTasks, downloadTasks in
dataTasks.forEach { $0.cancel() }
uploadTasks.forEach { $0.cancel() }
downloadTasks.forEach { $0.cancel() }
}
We use this code to cancel all requests (normal / upload / download) With Alamofire 4
Thanks a lot ;)
Thanks @jookes
Thanks @jookes
I am pissed of this error past 2 year in Swift ,whenever I hit the API Continuously
Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={NSUnderlyingError=0x608000458270 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={NSErrorPeerAddressKey=
Please help me to overcome this problem
Alamofire.SessionManager.default.session.getAllTasks { (tasks) in
tasks.forEach({$0.cancel()})
}
Please use this code for Cancel all request in swift 4.
Why do errors appear in console after cancelling tasks?
@jookes is there any call back option after cancelling all the requests. I need to perform certain task after all these calls get cancelled
Most helpful comment
let sessionManager = Alamofire.SessionManager.default sessionManager.session.getTasksWithCompletionHandler { dataTasks, uploadTasks, downloadTasks in dataTasks.forEach { $0.cancel() } uploadTasks.forEach { $0.cancel() } downloadTasks.forEach { $0.cancel() } }We use this code to cancel all requests (normal / upload / download) With Alamofire 4