Alamofire: Cancel request

Created on 5 May 2016  ·  3Comments  ·  Source: Alamofire/Alamofire

Hi, I am cancelling a request but after .cancel() callback is called without errors and with a valid response. I call the cancel on the viewDidDisappear method because users can leave the screen while continue loading.

support

Most helpful comment

Same problem with response.response = nil and cannot differentiate is this nil from cancel or timeout. Request did not finish and cancel still calls callback.

All 3 comments

This can certainly happen. The NSURLSession APIs are all asynchronous in nature. Calling cancel does not ensure the request is actually cancelled before it is able to complete.

Cheers. 🍻

But it should prevent calling the callback... Which is the workaround? I don't want to block the screen during the request. If users want to go back, they should be able to do that action.

Same problem with response.response = nil and cannot differentiate is this nil from cancel or timeout. Request did not finish and cancel still calls callback.

Was this page helpful?
0 / 5 - 0 ratings