Note: This framework has been deprecated. It is no longer being actively maintained and will not be updated for future versions of Swift or iOS.
ELReachability
is a simple Swift API for checking network reachability. ELReachability
is also designed to work well with, and to utilize other libraries in Electrode-iOS, or THG for short.
ELReachability
can be used to query the current reachability to the internet or to a particular host. It can also be used to receive callbacks when the reachability changes.
Setting up and checking reachability to the internet
// Create a Reachability instance
let theInternets = NetworkStatus.networkStatusForInternetConnection()
// Set up a callback
theInternets.startNetworkStatusMonitoring { status in
guard let connection = status.connection else {
print("Internet is not reachable")
return
}
switch connection {
case .cellular:
print("Internet is reachable via cellular connection")
case .wifi:
print("Internet is reachable via WiFi connection")
}
}
// Synchronous check
switch theInternets.connection {
case nil:
print("Internet is not reachable")
case .cellular?:
print("Internet is reachable via cellular connection")
case .wifi?:
print("Internet is reachable via WiFi connection")
}
// Stop monitoring
theInternets.stopNetworkStatusMonitoring()