Nice category that adds the ability to set the retry interval, retry count and progressiveness.

Overview

AFNetworking+RetryPolicy

Travis Version Platform Documentation Join the chat at https://gitter.im/AFNetworking-RetryPolicy/ License

If a request timed out, you usually have to call that request again by yourself. AFNetworking+RetryPolicy is an objective-c category that adds the ability to set the retry logic for requests made with AFNetworking.

Features

  • retryCount - How many times to try.
  • retryInterval - Time interval between attempts in seconds.
  • progressive - Next attempt will always take more time than the previous one. (Uses Exponentiation)
  • fatalStatusCodes - These will trigger failure block immediately when received and ends current retry.

Getting started

  • Installing through CocoaPods with pod 'AFNetworking+RetryPolicy'
  • Use #import "AFHTTPSessionManager+RetryPolicy.h" directive.

Want to try it first? Use pod try AFNetworking+RetryPolicy command.

Usage

Example

  • Simple GET request with AFNetworking+RetryPolicy could look like this:
    AFHTTPSessionManager *manager = [AFHTTPSessionManager new];
    [manager GET:@"foo" parameters:nil headers: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]];

Log

  • Enable to see what is happening by setting the AFHTTPSessionManager’s retryPolicyLogMessagesEnabled property to true. Disabled by default.

Requirements

  • AFNetworking 4.0 or later
  • Target iOS 9 or later
  • Target OS X/macOS 10.10 or later
  • Xcode 11 or later

Old versions

For AFNetworking 3 support

  • use version 1.x.

For AFNetworking 2 support*

  • use branch afn2-support.
  • Installing through CocoaPods with pod 'AFNetworking+RetryPolicy', git: 'https://github.com/kubatruhlar/AFNetworking-RetryPolicy.git' , branch: 'afn2-support'

*Will not be updated anymore.

For AFNetworking 1 support*

  • use branch afn1-support.
  • Installing through CocoaPods with pod 'AFNetworking+RetryPolicy', git: 'https://github.com/kubatruhlar/AFNetworking-RetryPolicy.git' , branch: 'afn1-support'

*Will not be updated anymore.

Author and credit

License

  • Like 👍 AFNetworking, this category is published under the MIT License. See LICENSE.md for details.
Comments
  • Support for AFNetworking 4.0.0. Older versions invalid due to UIWebView

    Support for AFNetworking 4.0.0. Older versions invalid due to UIWebView

    Pods won't update AFNetworking to 4.0.0 due to AFNetworking-RetryPolicy placing a version limit on it. I understand there are some API changes which will require work. Happy to help?

    important 
    opened by Seoras 2
  • can't use branch afn2-support on podfile

    can't use branch afn2-support on podfile

    I am trying to use this branch for AFNetworking2.x support, using the following line in my podfile:

    pod "AFNetworking+RetryPolicy", git: 'https://github.com/kubatruhlar/AFNetworking-RetryPolicy.git' , branch: 'afn2-support'

    i get the following error:

    Unable to find a specification for 'AFNetworking+RetryPolicy'

    the configuration seems to be ok, since the log says:

    Pre-downloading: AFNetworking+RetryPolicy from https://github.com/kubatruhlar/AFNetworking-RetryPolicy.git, branch afn2-support

    important 
    opened by fabionapodano 1
  • Call failure block back when fatal error occurred.

    Call failure block back when fatal error occurred.

    There is an issue when fatal error occurred and the failure block was not called. Therefore, would you please merge this pull request to fix this issue?

    opened by marslin1220 1
  • Make failure block optional

    Make failure block optional

    Some how

    - (NSURLSessionDataTask *)requestUrlWithRetryRemaining:(NSInteger)retryRemaining maxRetry:(NSInteger)maxRetry retryInterval:(NSTimeInterval)retryInterval progressive:(bool)progressive fatalStatusCodes:(NSArray<NSNumber *> *)fatalStatusCodes originalRequestCreator:(NSURLSessionDataTask *(^)(void (^)(NSURLSessionDataTask *, NSError *)))taskCreator originalFailure:(void(^)(NSURLSessionDataTask *task, NSError *))failure {
    

    method doesn't specify originalFailure block as nullable which can cause crashes if we pass null

    Original methods from AFNetworking take nullable blocks. ex) https://github.com/AFNetworking/AFNetworking/blob/master/AFNetworking/AFHTTPSessionManager.m#L125

    opened by junlee-qz 0
  • add retry function for data task with request

    add retry function for data task with request

    We use data task with request to send api, but found that your guys retry policy does not support data task, so I add this retry function for data task with request. Wish your guys can accept my pr, Thank you.

    opened by karosLi 1
Releases(2.0.0)
Owner
Jakub Truhlář
iOS Software Developer
Jakub Truhlář
Easy and lightweight network layer for creating different set of network requests like GET, POST, PUT, DELETE customizable with coders conforming to TopLevelDecoder, TopLevelEncoder

Easy and lightweight network layer for creating different set of network requests like GET, POST, PUT, DELETE customizable with coders conforming to TopLevelDecoder, TopLevelEncoder

Igor 2 Sep 16, 2022
A simple OAuth library for iOS with a built-in set of providers

SwiftyOAuth is a small OAuth library with a built-in set of providers and a nice API to add your owns. let instagram: Provider = .instagram(clientID:

Damien 477 Oct 15, 2022
Server-side Swift. The Perfect core toolset and framework for Swift Developers. (For mobile back-end development, website and API development, and more…)

Perfect: Server-Side Swift 简体中文 Perfect: Server-Side Swift Perfect is a complete and powerful toolbox, framework, and application server for Linux, iO

PerfectlySoft Inc. 13.9k Jan 6, 2023
🌏 A zero-dependency networking solution for building modern and secure iOS, watchOS, macOS and tvOS applications.

A zero-dependency networking solution for building modern and secure iOS, watchOS, macOS and tvOS applications. ?? TermiNetwork was tested in a produc

Bill Panagiotopoulos 90 Dec 17, 2022
StatusBarOverlay will automatically show a "No Internet Connection" bar when your app loses connection, and hide it again. It supports apps which hide the status bar and The Notch

StatusBarOverlay StatusBarOverlay will automatically show a "No Internet Connection" bar when your app loses connection, and hide it again. It support

Idle Hands Apps 160 Nov 2, 2022
Socket.io iOS and OSX Client compatible with v1.0 and later

SocketIO-Kit ⚠️ This project is no longer maintained. Please use the official framework Socket.IO-Client-Swift. SocketIO-Kit is a Socket.io iOS client

Ricardo Pereira 140 Mar 9, 2022
RestKit is a framework for consuming and modeling RESTful web resources on iOS and OS X

RestKit RestKit is a modern Objective-C framework for implementing RESTful web services clients on iOS and Mac OS X. It provides a powerful object map

The RestKit Project 10.2k Dec 29, 2022
NSURLSession network abstraction layer, using Codable and Decodable for response and Encodable for request. ⚙️🚀

SONetworking NSURLSession network abstraction layer, using Codable and Decodable for response and Encodable for request. Project Folder and File Struc

Ahmad AlSofi 4 Jan 28, 2022
Lightweight Networking and Parsing framework made for iOS, Mac, WatchOS and tvOS.

NetworkKit A lightweight iOS, Mac and Watch OS framework that makes networking and parsing super simple. Uses the open-sourced JSONHelper with functio

Alex Telek 30 Nov 19, 2022
Bonjour networking for discovery and connection between iOS, macOS and tvOS devices.

Merhaba Bonjour networking for discovery and connection between iOS, macOS and tvOS devices. Features Creating Service Start & Stop Service Stop Brows

Abdullah Selek 67 Dec 5, 2022
QwikHttp is a robust, yet lightweight and simple to use HTTP networking library for iOS, tvOS and watchOS

QwikHttp is a robust, yet lightweight and simple to use HTTP networking library. It allows you to customize every aspect of your http requests within a single line of code, using a Builder style syntax to keep your code super clean.

Logan Sease 2 Mar 20, 2022
Impervious is a privacy and security-focused browser with native DANE support and a decentralized p2p light client.

Impervious iOS The first browser with support for native DNS-Based Authentication of Named Entities (DANE) with true downgrade protection, and the fir

Impervious Inc 25 Jun 15, 2022
Beacon is a privacy and security-focused browser with native DANE support and a decentralized p2p light client.

Beacon iOS The first browser with support for native DNS-Based Authentication of Named Entities (DANE) with true downgrade protection, and the first b

Impervious Inc 25 Jun 15, 2022
Publish and discover services using Bonjour

Ciao Lib to publish and find services using mDNS Requirements Installation Usage License Requirements iOS 8.0+ / Mac OS X 10.10+ / tvOS 9.0+ Xcode 9.0

Alexandre Mantovani Tavares 55 Dec 14, 2022
🌸 Powerful Codable API requests builder and manager for iOS.

This lib is about network requests with blackjack, roulette and craps! Using it you will be able to convert your massive API layer code into an awesom

CodyFire 251 Jan 8, 2023
OAuth2 framework for macOS and iOS, written in Swift.

OAuth2 OAuth2 frameworks for macOS, iOS and tvOS written in Swift 5.0. ⤵️ Installation ?? Usage ?? Sample macOS app (with data loader examples) ?? Tec

Pascal Pfiffner 1.1k Jan 8, 2023
Swift/Obj-C HTTP framework with a focus on REST and JSON

Now Archived and Forked PMHTTP will not be maintained in this repository going forward. Please use, create issues on, and make PRs to the fork of PHMT

Postmates Inc. 509 Sep 4, 2022
Swift Paging is a framework that helps you load and display pages of data from a larger dataset from local storage or over network.

Swift Paging is a framework that helps you load and display pages of data from a larger dataset from local storage or over network. This approach allows your app to use both network bandwidth and system resources more efficiently. It's built on top of Combine, allowing you to harness its full power, handle errors easily, etc.

Gordan Glavaš 12 Dec 9, 2022
Websockets in swift for iOS and OSX

Starscream is a conforming WebSocket (RFC 6455) library in Swift. Features Conforms to all of the base Autobahn test suite. Nonblocking. Everything ha

Dalton 7.5k Jan 4, 2023