NetworkReachabilityManager
open class NetworkReachabilityManager
The NetworkReachabilityManager class listens for reachability changes of hosts and addresses for both cellular and
WiFi network interfaces.
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.
-
Defines the various states of network reachability.
See moreDeclaration
Swift
public enum NetworkReachabilityStatusextension NetworkReachabilityManager.NetworkReachabilityStatus: Equatable -
A closure executed when the network reachability status changes. The closure takes a single argument: the network reachability status.
Declaration
Swift
public typealias Listener = (NetworkReachabilityStatus) -> Void -
Default
NetworkReachabilityManagerfor the zero address and alistenerQueueof.main.Declaration
Swift
public static let `default`: NetworkReachabilityManager?
-
Whether the network is currently reachable.
Declaration
Swift
open var isReachable: Bool { get } -
Whether the network is currently reachable over the cellular interface.
Note
Using this property to decide whether to make a high or low bandwidth request is not recommended. Instead, set theallowsCellularAccesson anyURLRequests being issued.Declaration
Swift
open var isReachableOnCellular: Bool { get } -
Whether the network is currently reachable over Ethernet or WiFi interface.
Declaration
Swift
open var isReachableOnEthernetOrWiFi: Bool { get } -
DispatchQueueon which reachability will update.Declaration
Swift
public let reachabilityQueue: DispatchQueue -
Flags of the current reachability type, if any.
Declaration
Swift
open var flags: SCNetworkReachabilityFlags? { get } -
The current network reachability status.
Declaration
Swift
open var status: NetworkReachabilityStatus { get }
-
Creates an instance with the specified host.
Note
The
hostvalue must not contain a scheme, just the hostname.Declaration
Swift
public convenience init?(host: String)Parameters
hostHost used to evaluate network reachability. Must not include the scheme (e.g.
https). -
Creates an instance that monitors the address 0.0.0.0.
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.
Declaration
Swift
public convenience init?()
-
Starts listening for changes in network reachability status.
Note
Stops and removes any existing listener.
Declaration
Swift
@discardableResult open func startListening(onQueue queue: DispatchQueue = .main, onUpdatePerforming listener: @escaping Listener) -> BoolParameters
queueDispatchQueueon which to call thelistenerclosure..mainby default.listenerListenerclosure called when reachability changes.Return Value
trueif listening was started successfully,falseotherwise. -
Stops listening for changes in network reachability status.
Declaration
Swift
open func stopListening()
View on GitHub
Install in Dash
NetworkReachabilityManager Class Reference