Swiftpack.co - Package - Alamofire/AlamofireNetworkActivityIndicator

AlamofireNetworkActivityIndicator

Build Status CocoaPods Compatible Carthage Compatible Platform Twitter

Controls the visibility of the network activity indicator on iOS using Alamofire.

Features

  • [X] Automatic Management of Activity Indicator Visiblity
  • [X] Delay Timers to Mitigate Flicker
  • [X] Can Support URLSession Instances Not Managed by Alamofire
  • ☑ Comprehensive Test Coverage
  • Complete Documentation

Requirements

  • iOS 10.0+
  • Xcode 10.2+
  • Swift 5.0+

Dependencies

Communication

  • If you need help, use Stack Overflow. (Tag 'alamofire')
  • If you'd like to ask a general question, use Stack Overflow.
  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate Alamofire into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'AlamofireNetworkActivityIndicator', '~> 3.0'

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate Alamofire into your Xcode project using Carthage, specify it in your Cartfile:

github "Alamofire/AlamofireNetworkActivityIndicator" ~> 3.0

Swift Package Manager (requires Xcode 11)

  1. Select File > Swift Packages > Add Package Dependency. Enter https://github.com/Alamofire/AlamofireNetworkActivityIndicator in the "Choose Package Repository" dialog.
  2. In the next page, specify the version resolving rule as "Up to Next Major" with "3.0.0" as its earliest version.
  3. After Xcode checking out the source and resolving the version, you can choose the "AlamofireNetworkActivityIndicator" library and add it to your app target.

Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate AlamofireNetworkActivityIndicator into your project manually.

Embedded Framework

  • Open up Terminal, cd into your top-level project directory, and run the following command "if" your project is not initialized as a git repository:
$ git init
  • Add AlamofireNetworkActivityIndicator as a git submodule by running the following command:
$ git submodule add https://github.com/Alamofire/AlamofireNetworkActivityIndicator.git
  • Open the new AlamofireNetworkActivityIndicator folder, and drag the AlamofireNetworkActivityIndicator.xcodeproj into the Project Navigator of your application's Xcode project.

    It should appear nested underneath your application's blue project icon. Whether it is above or below all the other Xcode groups does not matter.

  • Select the AlamofireNetworkActivityIndicator.xcodeproj in the Project Navigator and verify the deployment target matches that of your application target.

  • Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the "Targets" heading in the sidebar.

  • In the tab bar at the top of that window, open the "General" panel.

  • Click on the + button under the "Embedded Binaries" section.

  • You will see two different AlamofireNetworkActivityIndicator.xcodeproj folders each with two different versions of the AlamofireNetworkActivityIndicator.framework nested inside a Products folder.

    It does not matter which Products folder you choose from.

  • Select the AlamofireNetworkActivityIndicator.framework and add it to your project.

  • And that's it!

    The AlamofireNetworkActivityIndicator.framework is automagically added as a target dependency, linked framework and embedded framework in a copy files build phase which is all you need to build on the simulator and a device.


Usage

The NetworkActivityIndicatorManager manages the state of the network activity indicator. To begin using it, all that is required is to enable the shared instance in application:didFinishLaunchingWithOptions: in your AppDelegate.

NetworkActivityIndicatorManager.shared.isEnabled = true

By enabling the shared manager for the system, the network activity indicator will show and hide automatically as Alamofire requests start and complete.

Notifications

The NetworkActivityIndicatorManager manages the currently active network request count by observing notifications emitted from Alamofire. By observing the task state changes, the shared manager always knows how many requests are currently active and updates the visibility of the activity indicator accordingly.

It is possible to have the shared manager observe URLSession instances not inside Alamofire. You will need to emit matching notifications from the URLSessionDelegate matching those found in Alamofire.

Delay Timers

In order to make the activity indicator experience for a user as pleasant as possible, there need to be start and stop delays added in to avoid flickering. There are two such delay timers built into the shared manager.

Start Delay

The start delay is a time interval indicating the minimum duration of networking activity that should occur before the activity indicator is displayed. This helps avoid needlessly displaying the indicator for really fast network requests. The default value is 1.0 second. You can easily change the default value if needed.

NetworkActivityIndicatorManager.shared.startDelay = 1.0

Completion Delay

The completion delay is a time interval indicating the duration of time that no networking activity should be observed before dismissing the activity indicator. This allows the activity indicator to be continuously displayed between multiple network requests. Without this delay, the activity indicator tends to flicker. The default value is 0.2 seconds. You can easily change the default value if needed.

NetworkActivityIndicatorManager.shared.completionDelay = 0.2

FAQ

Why is this not in Alamofire?

In order to allow Alamofire to continue to be used in App Extensions, this logic could not be included in the Alamofire framework. In order to submit an App Extension to the App Store, it can only be linked against frameworks that specify they only use App Extension safe APIs. Since we want users to be able to use Alamofire in App Extensions, we MUST set the Require Only App Extension Safe APIs to true. Because of this, we cannot call non-safe App Extension APIs in the Alamofire framework. Controlling the activity indicator on iOS is done through non-safe App Extension APIs. Because of this, a separate library needed to be created.

But what about availability you say? Doesn't help in this case because availability checks still compile all the code. We could not use #if os(iOS) either because you cannot compile out logic specifically for iOS, but not for an iOS App Extension.


Credits

Alamofire is owned and maintained by the Alamofire Software Foundation. You can follow them on Twitter at @AlamofireSF for project updates and releases.

Donations

The ASF is looking to raise money to officially stay registered as a federal non-profit organization. Registering will allow us members to gain some legal protections and also allow us to put donations to use, tax free. Donating to the ASF will enable us to:

  • Pay our yearly legal fees to keep the non-profit in good status
  • Pay for our mail servers to help us stay on top of all questions and security issues
  • Potentially fund test servers to make it easier for us to test the edge cases
  • Potentially fund developers to work on one of our projects full-time

The community adoption of the ASF libraries has been amazing. We are greatly humbled by your enthusiasm around the projects, and want to continue to do everything we can to move the needle forward. With your continued support, the ASF will be able to improve its reach and also provide better legal safety for the core members. If you use any of our libraries for work, see if your employers would be interested in donating. Any amount you can donate today to help us reach our goal would be greatly appreciated.

paypal

License

AlamofireNetworkActivityIndicator is released under the MIT license. See LICENSE for details.

Github

link
Stars: 603

Dependencies

Used By

Total: 0

Releases

Alamofire 5 Compatibility - 2020-02-17 23:20:03

Released on 2020-002-17. All issues associated with this milestone can be found using this filter.

Added

AppStore Connect Submission Fix - 2019-05-04 21:16:06

Released on 2019-05-04. All issues associated with this milestone can be found using this filter.

Fixed

  • Issue with AppStore submissions where the pre-release version in the bundle short versions string was being rejected when built with Carthage or as a submodule.
  • Issue in the Carthage installation instructions in the README.

AF5b5 and Task Tracking - 2019-04-13 18:28:45

Released on 2019-04-13. All issues associated with this milestone can be found using this filter.

Updated

  • Project to require Alamofire 5.0.0-beta.5+ as a dependency.
  • Activity tracking to monitor task events rather than request events to improve accuracy.

AF5, Swift 5 only, and Improved Request Tracking - 2019-04-10 17:57:40

Released on 2019-04-10. All issues associated with this milestone can be found using this filter.

Added

  • New requestDidStart and requestDidStop APIs based on requestIDs to replace the increment and decrement activity count APIs.

Updated

  • Project to use Swift 5 only and require Alamofire 5.0.0-beta.4+ as a dependency.

Fixed

  • Issue where activity count could become negative causing the network activity indicator to not display correctly.

Indicating Compatibility - 2019-04-06 20:50:40

Released on 2019-04-06. All issues associated with this milestone can be found using this filter.

Updated

  • Project to use Swift 4 as the default language version for compatiblity with the Swift 5 compiler and Xcode 10.2.

Swift 4.2! - 2018-09-15 23:51:46

Released on 2018-09-15. All issues associated with this milestone can be found using this filter.

Updated

  • Code and dependencies for Xcode 10 and Swift 4.2.

Fixed

Xcode 9.3 and Swift 4.1 Support - 2018-04-01 01:08:08

Released on 2018-03-31. All issues associated with this milestone can be found using this filter.

Added

  • Jazzy docs.
  • Pull request and issue templates.

Updated

  • Project settings and dependencies for Xcode 9.3 and Swift 4.1.

Fixed

  • Swift Package Manager integration by removing Swift Package Manager support.

Xcode 9 and Swift 4.0 Support - 2017-06-17 02:49:57

All issues associated with this milestone can be found using this filter.

Updated

  • The Alamofire submodule to the 4.5.0 release along with all dependency requirements.
  • Updated all project settings to Xcode 9 for support for Swift 3.1, 3.2, and 4.0.

Fixed

iOS 8.0 Deployment Target - 2016-11-21 04:08:49

All issues associated with this milestone can be found using this filter.

Updated

  • The deployment targets to iOS 8.0 and macOS 10.10 and updated project settings.
  • The Alamofire submodule to the 4.2.0 release.

Thread Safety and Race Condition Bug Fixes - 2016-10-01 22:49:21

All issues associated with this milestone can be found using this filter.

Added

  • New .swift-version file to repo and reactivated pod lib lint in Travis file.
  • The OS_ACTIVITY_MODE environment variable to disable excessive logging.

Updated

  • The Alamofire submodule to the 4.0.1 release.

Fixed

  • Issue where delay timers were being added to main run loop from non-main queues.
  • Issue where spinner could be left up indefinitely due to decrement race condition.

Swift 3 Support alongside Alamofire 4 - 2016-09-11 11:09:15

All issues associated with this milestone can be found using this filter.

Updated

  • All source, test and example logic as well as project settings to compile against the Xcode 8 beta releases.
  • Deployment target and README requirements to iOS 9.0.
  • All source and test APIs to match Swift 3 design guidelines.
  • The Cartfile and the Alamofire submodule to the 4.0.0 release.
  • The docstrings to use the new Swift 3 formatting guidelines.
  • The podspec version to 2.0.0 and bumped deployment target and dependency.
  • Project settings by running Swift 3 conversion tool and setting ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES to YES.
  • The travis-ci yaml file to build against Xcode 8 osx_image.
  • Code signing to automatic with no team and updated code signing identities.

Swift 2.3 Support - 2016-09-08 08:25:31

All issues associated with this milestone can be found using this filter.

Updated

  • The build status badge in the README now only reports the status of the master branch.
  • The source, test and example code along with project settings to support Swift 2.2 and Swift 2.3 simultaneously.
  • Updated the travis yaml file for Swift 2.3 and the new OS target versions.
  • Updated the Cartfile and Alamofire submodule to the 3.5.0 release.
  • Updated Xcode project settings based on Xcode 8 GM recommendations.
  • Code coverage generation is now disabled on framework targets to improve stability.

Swift 2.2 Support - 2016-03-24 01:03:06

All issues associated with this milestone can be found using this filter.

Updated

  • The Alamofire submodule to the 3.3.0 release along with the Cartfile and Podspec dependencies.
  • All source code, tests and example logic to use Swift 2.2 conventions.
  • The required version of Xcode to 7.3 in the README.

Initial Release - 2016-02-08 15:13:34

All issues associated with this milestone can be found using this filter.

Added

  • Initial release of AlamofireNetworkActivityIndicator.