NetworkActivityIndicatorManager

public class NetworkActivityIndicatorManager

The NetworkActivityIndicatorManager manages the state of the network activity indicator in the status bar. When enabled, it will listen for notifications indicating that a URL session task has started or completed and start animating the indicator accordingly. The indicator will continue to animate while the internal activity count is greater than zero.

To use the NetworkActivityIndicatorManager, the shared instance should be enabled in the application:didFinishLaunchingWithOptions: method in the AppDelegate. This can be done with the following:

NetworkActivityIndicatorManager.shared.isEnabled = true

By setting the isEnabled property to true for the shared instance, the network activity indicator will show and hide automatically as Alamofire requests start and complete. You should not ever need to call incrementActivityCount and decrementActivityCount yourself.

Properties

  • The shared network activity indicator manager for the system.

    Declaration

    Swift

    public static let shared: NetworkActivityIndicatorManager
  • A boolean value indicating whether the manager is enabled. Defaults to false.

    Declaration

    Swift

    public var isEnabled: Bool { get set }
  • A boolean value indicating whether the network activity indicator is currently visible.

    Declaration

    Swift

    public private(set) var isNetworkActivityIndicatorVisible: Bool { get set }
  • A closure executed when the network activity indicator visibility changes.

    Declaration

    Swift

    public var networkActivityIndicatorVisibilityChanged: ((Bool) -> Void)?
  • A time interval indicating the minimum duration of networking activity that should occur before the activity indicator is displayed. Defaults to 1.0 second.

    Declaration

    Swift

    public var startDelay: TimeInterval
  • 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. Defaults to 0.2 seconds.

    Declaration

    Swift

    public var completionDelay: TimeInterval

Request Tracking

  • Adds the requestID as an active request driving the activity indicator.

    This method results in a no-op if the request is already being tracked.

    Declaration

    Swift

    public func requestDidStart(requestID: String)

    Parameters

    requestID

    The request identifier.

  • Removes the requestID from the set of active requests driving the activity indicator.

    This method results in a no-op if the request is not being tracked.

    Declaration

    Swift

    public func requestDidStop(requestID: String)

    Parameters

    requestID

    The request identifier.