Last active
September 5, 2016 03:42
-
-
Save zxx/b20a25f08113ffc0594c to your computer and use it in GitHub Desktop.
iOS HTTP 请求失败后重试 n 次
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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