How to cancel all Alamofire requests when user entered background or app is terminated?
I have researched everything on the Internet including these Stack Overflow links;
I have tried;
Alamofire.SessionManager.default.session.getTasksWithCompletionHandler { dataTasks, uploadTasks, downloadTasks in
dataTasks.forEach { $0.cancel() }
uploadTasks.forEach { $0.cancel() }
downloadTasks.forEach { $0.cancel() }
}
But tasks are always empty, eventhough there are some.
And also I have tried this;
Alamofire.SessionManager.default.session.invalidateAndCancel()
It invalidates the session but revalidation or recreating the session is not working as expected.
How can I stop all active Alamofire requests completely? Any help would be appreciated.