Skip to content

Feature Request: Retry count #393

anthonycmain opened this Issue Jun 29, 2012 · 3 comments

3 participants


Until one of our devs finds the time, I was wondering if there were any plans, or anyone already has extending the library to have a retry count for connections.

I.e Im looking for a feature to retry a download 3 times if it times out/fails cause of a broken connection. Perhaps with a sleep period between attempts.

It would save me writing extra subs each time to support this feature

mattt commented Jun 29, 2012

Thanks for your suggestion, @anthonycmain.

This is something that a few people have requested, but each each use case had surprisingly different requirements in what the behavior should be, which leads me to believe that a general solution that's useful for all relevant cases is intractable.

I'm of the opinion that request retrying is an application concern (or perhaps even something for the user to initiate); it's not all that difficult to implement yourself:

- (void)downloadFileRetryingNumberOfTimes:(NSUInteger)ntimes 
                                  success:(void (^)(id responseObject))success 
                                  failure:(void (^)(NSError *error))failure
    if (ntimes <= 0) {
        if (failure) {
            NSError *error = ...;
    } else {
        [self getPath:@"/path/to/file" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if (success) {
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            [self downloadFileRetryingNumberOfTimes:ntimes - 1 success:success failure:failure];

Or something like that—essentially just a basic recursive method. I hope that helps.

@mattt mattt closed this Jun 29, 2012

Brilliant nice response will do the job fine, think I might just add an additional sleep parameter, will share here if I do so


sorry for digging this out, but I need some advice that, should we be careful about retain circle when recursiving for self?

 failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            [self downloadFileRetryingNumberOfTimes:ntimes - 1 success:success failure:failure];

the block hold self, and the next recursive downloadFileRetryingNumberOfTimes will lead to self hold the block?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.