I use Alamofire
to send a download request. I am handling Success
and Failure
cases as shown below.
Alamofire.request {
case Success:
// Update UI
case Failure:
// Show Alert message (error!.localizedDescription)
}
Everything is perfectly fine.
When I go back, in viewWillDisappear
, I cancel any ongoing request. The issue is, canceling the request throws the error message and that triggers the alert when I am not on that screen.
To my knowledge, I can take two actions.
viewController
is aliveBool
variable in viewWillDisappear
, which is a simple solutionHow to handle the situation?
Also how to check point 1 & 2?
If you are able to get the reason why it has failed, you should go with that, so: Check the condition if the error is created due to request cancel
.
Option 2 is fragile, because you are relying on the UIViewController
's life cycle. Option 3 will only make your logic more cumbersome, via a new flag. Keep it simple