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.
- iOS 8.0+
- Xcode 9.0+
- Swift 4.0+
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()
yarp?.addHandler("key1", handler: { (yarp) in
if let reachable = yarp.isReachable {
print("block yarp has reachable-ness: \(reachable)")
}
})
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)
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)"
}
}
}
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
To integrate Yarp into your Xcode project using CocoaPods, specify it in your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '11.0'
use_frameworks!
target '<Your Target Name>' do
pod 'Yarp', '~> 1.0.0'
end
Then, run the following command:
$ pod install
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate Yarp into your Xcode project using Carthage, specify it in your Cartfile
:
github "Vectorform/Yarp" ~> 1.0.0
Run carthage update
to build the framework and drag the built Yarp.framework
into your Xcode project.
If you prefer not to use any of the listed dependency managers, you can integrate Yarp into your project manually.
Jeff Meador, [email protected]
Cory Bechtel, [email protected]
Yarp is available under the BSD license. See the LICENSE file for more info.