Yarp 1.0.0

Yarp 1.0.0

TestsTested
LangLanguage SwiftSwift
License BSD
ReleasedLast Release Oct 2017
SwiftSwift Version 4.0
SPMSupports SPM

Maintained by Cory, Jeff Meador.



Yarp 1.0.0

Created and maintained by Vectorform.

Yarp (Yet another reachability pod) is a reachability framework with a focus on reliability and simplicity. Yarp fully supports IPv6 and IPv4. Yarp allows you to observe changes in reachability using blocks or notifications.

Requirements

  • iOS 8.0+
  • Xcode 9.0+
  • Swift 4.0+

Initilize Yarp Object

The IPv4 addresses in the below example can be switched out for their IPv6 counterparts.
In versions prior to Yarp 1.0.0, IP addresses would not perform an initial callback on init. In 1.0.0 they now return a callback.

//base init defaults to "0.0.0.0" which is Apple's special internet reachability address
let yarp: Yarp? = Yarp()

//Custom hostname init
let yarp: Yarp? = Yarp(hostName: "www.google.com") //or "http://216.58.195.238" either will work

//Custom Address init
let yarp: Yarp? = Yarp(hostAddress: "216.58.195.238")
yarp?.start()

Listening Methods

Handler Block

yarp?.addHandler("key1", handler: { (yarp) in
    if let reachable = yarp.isReachable {
        print("block yarp has reachable-ness: \(reachable)")
    }
})

OR Notification Observer

You can listen for the notification sent from Yarp. If you have only one Yarp object you can safely set the object parameter to nil, but if you use more than one to monitor multiple hosts, then passing the object parameter into the addObserver function will make sure that you only get that objects reachability notifications.

//listen for ANY Yarp notification
NotificationCenter.default.addObserver(self, selector: #selector(reachabilityChanged, name: Yarp.StatusChangedNotification, object: nil)

// OR

//listen for a specific Yarp notification
NotificationCenter.default.addObserver(self, selector: #selector(reachabilityChanged, name: Yarp.StatusChangedNotification, object: yarpObject)

Set Notification handlers

func reachabilityChanged(notification: Notification) {
        if let yarp = notification.object as? Yarp {
          //Note: isReachable will likely never be null here
            if let reachable = yarp.isReachable {
                defaultStatusLabel.text = "Default isReachable: \(reachable)"
            }
        }
    }

Installation

Manually

If you prefer not to use any of the listed dependency managers, you can integrate Yarp into your project manually.

Authors

Jeff Meador, [email protected]

Cory Bechtel, [email protected]

License

Yarp is available under the BSD license. See the LICENSE file for more info.