Skip to content

Latest commit

 

History

History
48 lines (34 loc) · 2.56 KB

File metadata and controls

48 lines (34 loc) · 2.56 KB

AFNetworking+RetryPolicy

  • 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.). failure is called no earlier then retryCount = 0, only fatalStatusCodes finishes the request earlier.

Allows

  • 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.

Installation

  1. Add the AFNetworking+RetryPolicy category to your project as a regular library.
  2. Use #import "AFNetworking+RetryPolicy.h"

Usage (Example)

  • Simple GET request 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).

Author and credit

License

  • Like 👍 AFNetworking, this category is under the MIT License (MIT). Copyright © 2016 Jakub Truhlar