Skip to content

Latest commit

 

History

History
34 lines (25 loc) · 911 Bytes

RespondingToNetworkActivity.md

File metadata and controls

34 lines (25 loc) · 911 Bytes

Responding to network activity

To listen to changes on the network activity a closure can be set, for example:

NetworkServiceActivity.activityChangeHandler = { isActive in
  application.isNetworkActivityIndicatorVisible = isActive
}

It is recommended that this is setup on application launch, for example:

import UIKit
import TABResourceLoader

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

  var window: UIWindow?

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    setupNetworkActivityHandler(for: application)
    return true
  }

  private func setupNetworkActivityHandler(for application: UIApplication) {
    NetworkServiceActivity.activityChangeHandler = { isActive in
      application.isNetworkActivityIndicatorVisible = isActive
    }
  }
  
}