Skip to content

Instantly share code, notes, and snippets.

@zxx
Last active September 5, 2016 03:42
Show Gist options
  • Save zxx/b20a25f08113ffc0594c to your computer and use it in GitHub Desktop.
Save zxx/b20a25f08113ffc0594c to your computer and use it in GitHub Desktop.
iOS HTTP 请求失败后重试 n 次
// https://github.com/AFNetworking/AFNetworking/issues/393
- (void)downloadFileRetryingNumberOfTimes:(NSUInteger)ntimes
success:(void (^)(id responseObject))success
failure:(void (^)(NSError *error))failure
{
if (ntimes <= 0) {
if (failure) {
NSError *error = ...;
failure(error);
}
} else {
[self getPath:@"/path/to/file" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
if (success) {
success(...);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[self downloadFileRetryingNumberOfTimes:ntimes - 1 success:success failure:failure];
}];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment