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
OlaStatuseumerates three boiled down host states, derived from SCNetworkReachabilityFlags.unknownreachablecellularOlais the main object of this module, it implements the tinyReachingAPI:Exports
Creating a Probe
Each
Olaobject is dedicated to monitoring a specific host.hostThe 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
trueif installing thecallbackhas been successful.Invalidates the probe removing the callback.
Install
📦 Add
https://github.com/michaelnisi/olato your package manifest.License
MIT