WillowTreeReachability 2.0.4

WillowTreeReachability 2.0.4

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jun 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Erik LaManna.



  • By
  • WillowTree, Inc.

by WillowTree, Inc. We're hiring! Come join our team!

Simple Swift class for monitoring network reachability. This class uses a subscription model to notify listeners of network status changes. Multiple listeners may be added to a single Reachability instance.

Installation

CocoaPods:

pod 'WillowTreeReachability'

Carthage:

github "willowtreeapps/WillowTreeReachability" >= 2.0

Usage

To start Reachability, begin by initializing the class to check for either host reachability or general reachability as shown below:

import WillowTreeReachability

// Reachability for specific host
let reachability = Monitor(withURL: NSURL(string: "http://www.willowtreeapps.com")!)

// General internet Reachability
let reachability = Monitor()

Please note that WillowTreeReachability uses optional initializers and if there is an error creating the reachability connection, then nil is returned.

Asynchronous Notifications

WillowTreeReachability utilizes asynchronous network status monitoring to update the application of network changes. The notifier can be started by calling startMonitoring and adding a subscriber through the addReachabilitySubscriber function. An example is shown below.

reachability?.start()

reachabilitySubscription = reachability?.addSubscription(using: self)

}

The subscription should be held strongly by the callee to keep the subscription active.

Stopping Reachability

In order to properly clean up when stopping the reachability notifications, the stop function should be called.