Yarp 0.1.2

Yarp 0.1.2

TestsTested
LangLanguage SwiftSwift
License BSD
ReleasedLast Release Apr 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Cory, Jeff Meador.


Downloads

Total9
Week0
Month2

Installs

Apps3
powered by Segment

GitHub

Stars5
Watchers5
Forks0
Issues0
Contributors2
Pull Requests0

Code

Files1
LOCLines of Code 132


Yarp 0.1.2

Yarp

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.

Initilize Yarp Object

Note: the IPv4 addresses in the below example can be switched out for their IPv6 counterparts.

//base init defaults to "0.0.0.0" which is Apple's special internet reachability address, Does NOT return an initial callback
let yarp: Yarp? = Yarp()

//Custom hostname init, DOES make an initial callback when first started
let yarp: Yarp? = Yarp(hostName: "www.google.com") //or "http://216.58.195.238" either will work

//Custom Address init, does NOT return an initial callback when started
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

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Authors

Jeff Meador, [email protected]

Cory Bechtel, [email protected]

License

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