Skip to content

Instantly share code, notes, and snippets.

@axldyb
Created December 3, 2013 07:24
Show Gist options
  • Save axldyb/7765269 to your computer and use it in GitHub Desktop.
Save axldyb/7765269 to your computer and use it in GitHub Desktop.
Method retrying AFNetworking request n number of times. Not a perfect implementation, but this is just for saving the idea.
- (void)downloadFileRetryingNumberOfTimes:(NSUInteger)numberOfTimes
success:(void (^)(id responseObject))success
failure:(void (^)(NSError *error))failure
{
if (numberOfTimes <= 0) {
if (failure) {
NSError *error = ...;
failure(error);
}
} else {
[self getPath:@"/path" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
if (success) {
success(...);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[self downloadFileRetryingNumberOfTimes:numberOfTimes - 1 success:success failure:failure];
}];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment