I have recently migrated from ASIHTTPRequest to AFNetworking, which has been great. However, the server that I am connecting with has some issues and sometimes causes my requests to timeout. When using ASIHTTPRequest it was possible to setup a retry count on a request in the event of a timeout using the following selector
-setNumberOfTimesToRetryOnTimeout:
This can be further referenced in this post, Can an ASIHTTPRequest be retried?
This is AFNetworking if you are unfamiliar https://github.com/AFNetworking/AFNetworking#readme
I was unable to find an equivalent api in AFNetworking, has anyone found a solution for retrying network requests in the event of timeout using AFNetworking?
In my case, I frequently required retry functionality so I came up wit this retry policy category that will help you with that AFNetworking+RetryPolicy
With respect to AFNetworking 3.0 it could serve well.
I implemented private method in my ApiClient class:
Example of usage:
Based on your answers, you could do something even more generic (and tricky) by using a block taking as parameter a block :
Then surround your asynchronous HTTP requests like the following :
This way the retries wait for the HTTP request to finish and you don't have to implement the retry loop in each request methods.
Matt Thompson developer of AFNetworking was kind enough to answer this for me. Below is the github link explaining the solution.
https://github.com/AFNetworking/AFNetworking/issues/393
Basically, AFNetworking doesn't support this functionality. It is left to the developer to implement on a case by case basis as shown below (taken from Matt Thompson's answer on github)