I am sending a request which is triggered based on timer. But if I press the back button the request still seems to be active and the response in turns crashes the app. Kind
did you try this solution:
let sessionManager = Alamofire.SessionManager.default
sessionManager.session.getTasksWithCompletionHandler { dataTasks, uploadTasks, downloadTasks in
dataTasks.forEach { $0.cancel() }
uploadTasks.forEach { $0.cancel() }
downloadTasks.forEach { $0.cancel() }
}
i also add a check to verify if is this the request that i want to cancel:
dataTasks.forEach
{
if ($0.originalRequest?.url?.absoluteString == url)
{
$0.cancel()
}
}