NetworkReachabilityManager - SwiftDocOrg/Alamofire GitHub Wiki
!(os(watchOS) || os(Linux))-
The
NetworkReachabilityManagerclass listens for reachability changes of hosts and addresses for both cellular and WiFi network interfaces.open class NetworkReachabilityManager
Reachability can be used to determine background information about why a network operation failed, or to retry network requests when a connection is established. It should not be used to prevent a user from initiating a network request, as it's possible that an initial request may be required to establish reachability.
!(os(watchOS) || os(Linux))-
A closure executed when the network reachability status changes. The closure takes a single argument: the network reachability status.
public typealias Listener = (NetworkReachabilityStatus) -> Void
!(os(watchOS) || os(Linux))-
Creates an instance with the specified host.
public convenience init?(host: String)
- host: Host used to evaluate network reachability. Must not include the scheme (e.g.
https).
- host: Host used to evaluate network reachability. Must not include the scheme (e.g.
!(os(watchOS) || os(Linux))-
Creates an instance that monitors the address 0.0.0.0.
public convenience init?()
Reachability treats the 0.0.0.0 address as a special token that causes it to monitor the general routing status of the device, both IPv4 and IPv6.
!(os(watchOS) || os(Linux))-
Default
NetworkReachabilityManagerfor the zero address and alistenerQueueof.main.let `default`
!(os(watchOS) || os(Linux))-
Whether the network is currently reachable.
var isReachable: Bool
!(os(watchOS) || os(Linux))-
Whether the network is currently reachable over the cellular interface.
var isReachableOnCellular: Bool
!(os(watchOS) || os(Linux))-
Whether the network is currently reachable over Ethernet or WiFi interface.
var isReachableOnEthernetOrWiFi: Bool
!(os(watchOS) || os(Linux))-
DispatchQueueon which reachability will update.let reachabilityQueue
!(os(watchOS) || os(Linux))-
Flags of the current reachability type, if any.
var flags: SCNetworkReachabilityFlags?
!(os(watchOS) || os(Linux))-
The current network reachability status.
var status: NetworkReachabilityStatus
!(os(watchOS) || os(Linux))-
Starts listening for changes in network reachability status.
@discardableResult open func startListening(onQueue queue: DispatchQueue = .main, onUpdatePerforming listener: @escaping Listener) -> Bool
- queue:
DispatchQueueon which to call thelistenerclosure..mainby default. - listener:
Listenerclosure called when reachability changes.
trueif listening was started successfully,falseotherwise. - queue:
!(os(watchOS) || os(Linux))-
Stops listening for changes in network reachability status.
open func stopListening()