The Ola Swift package lets you check network reachability of a named host. You can set a callback to run when the reachability of the host has changed. Ola is a simple Swift wrapper around some of Apple’s System Configuration APIs, making them easier to use.
Example
import Foundation
import os.log
let host = "1.1.1.1"
var probe = Ola(host: host, log: .default)
probe?.activate { status in
print("host status: (\(host), \(String(describing: status)))")
}
sleep(10)
probe?.invalidate()
probe = nil
print("OK")
Ola
The Ola Swift package lets you check network reachability of a named host. You can set a callback to run when the reachability of the host has changed. Ola is a simple Swift wrapper around some of Apple’s System Configuration APIs, making them easier to use.
Example
Types
OlaStatus
eumerates three boiled down host states, derived from SCNetworkReachabilityFlags.unknown
reachable
cellular
Ola
is the main object of this module, it implements the tinyReaching
API:Exports
Creating a Probe
Each
Ola
object is dedicated to monitoring a specific host.host
The name of the host to monitor.Checking Host Reachability
The common use case is to synchronously—not on the main thread though QA1693—check if a given host is reachable.
Returns the reachability of the host: unknown, reachable, or cellular.
Same as
reach()
, but non-blocking, executing on a system-provided global concurrent dispatch queues.Monitoring Host
A less common use case is getting notified, when the state of a given host has changed. For example, to reason if it’s appropiate to issue a request.
Returns
true
if installing thecallback
has been successful.Invalidates the probe removing the callback.
Install
📦 Add
https://github.com/michaelnisi/ola
to your package manifest.License
MIT