-
If the request timed out, you usually have to call the request again by yourself. AFNetworking+RetryPolicy handles that for you.
-
AFNetworking+RetryPolicy category adds the ability to set the retry interval, retry count and progressive (uses power rule e.g. interval = 3 -> 3, 9, 27 etc.).
failureis called no earlier thenretryCount= 0, onlyfatalStatusCodesfinishes the request earlier.
- How many times to try.
- Time interval between attempts in seconds.
- Progressive - next attempt will always take more time then the previous one if set.
- Set fatal status codes. These will trigger failure block immediately when received, ends all retry counts.
-
Category uses AFNetworking 3.0 and above.
-
For AFNetworking 1 support, use branch
afn1-support. Will not be updated anymore. -
For AFNetworking 2 support, use branch
afn2-support. Will not be updated anymore.
- Add the AFNetworking+RetryPolicy category to your project as a regular library.
- Use
#import "AFNetworking+RetryPolicy.h"
- Simple
GETrequest will look like this.
AFHTTPSessionManager *manager = [AFHTTPSessionManager new];
[manager GET:@"foo" parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
NSLog(@"%@", responseObject);
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"%@", error.localizedDescription);
} retryCount:5 retryInterval:2.0 progressive:false fatalStatusCodes:@[@401, @403]];- You can also turn on the logging in the category to see what happens (
kDebugLoggingEnabled = true).
- This library is open-sourced and maintained by Jakub Truhlar.
- Based on @shaioz solution.
- AFNetworking is owned and maintained by the Alamofire Software Foundation.
- Like 👍 AFNetworking, this category is under the MIT License (MIT). Copyright © 2016 Jakub Truhlar
