https://github.com/willowtreeapps/willowtreereachability
Simple Swift class for monitoring network reachability.
https://github.com/willowtreeapps/willowtreereachability
Last synced: 2 days ago
JSON representation
Simple Swift class for monitoring network reachability.
- Host: GitHub
- URL: https://github.com/willowtreeapps/willowtreereachability
- Owner: willowtreeapps
- License: mit
- Created: 2015-08-28T21:17:48.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-06-14T15:06:01.000Z (about 8 years ago)
- Last Synced: 2025-04-22T17:17:34.779Z (2 months ago)
- Language: Swift
- Size: 71.3 KB
- Stars: 6
- Watchers: 51
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/willowtreeapps/WillowTreeReachability?branch=master)
# WillowTreeReachability
by [WillowTree, Inc.](http://www.willowtreeapps.com) *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:
```ruby
pod 'WillowTreeReachability'
```Carthage:
```ruby
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:
```swift
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.