NetworkReachabilityManager
open class NetworkReachabilityManager
The NetworkReachabilityManager
class listens for reachability changes of hosts and addresses for both WWAN 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.
- unknown: It is unknown whether the network is reachable.
- notReachable: The network is not reachable.
- reachable: The network is reachable.
Declaration
Swift
public enum NetworkReachabilityStatus
-
Defines the various connection types detected by reachability flags.
- ethernetOrWiFi: The connection type is either over Ethernet or WiFi.
- wwan: The connection type is a WWAN connection.
Declaration
Swift
public enum ConnectionType
-
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
-
Whether the network is currently reachable.
Declaration
Swift
open var isReachable: Bool { get }
-
Whether the network is currently reachable over the WWAN interface.
Declaration
Swift
open var isReachableOnWWAN: Bool { get }
-
Whether the network is currently reachable over Ethernet or WiFi interface.
Declaration
Swift
open var isReachableOnEthernetOrWiFi: Bool { get }
-
The current network reachability status.
Declaration
Swift
open var networkReachabilityStatus: NetworkReachabilityStatus { get }
-
The dispatch queue to execute the
listener
closure on.Declaration
Swift
open var listenerQueue: DispatchQueue
-
A closure executed when the network reachability status changes.
Declaration
Swift
open var listener: NetworkReachabilityManager.Listener?
-
Undocumented
Declaration
Swift
open var flags: SCNetworkReachabilityFlags? { get }
-
Undocumented
Declaration
Swift
open var previousFlags: SCNetworkReachabilityFlags
-
Creates a
NetworkReachabilityManager
instance with the specified host.Declaration
Swift
public convenience init?(host: String)
Parameters
host
The host used to evaluate network reachability.
Return Value
The new
NetworkReachabilityManager
instance. -
Creates a
NetworkReachabilityManager
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?()
Return Value
The new
NetworkReachabilityManager
instance. -
Undocumented
Declaration
Swift
deinit
-
Starts listening for changes in network reachability status.
Declaration
Swift
@discardableResult open func startListening() -> Bool
Return Value
true
if listening was started successfully,false
otherwise. -
Stops listening for changes in network reachability status.
Declaration
Swift
open func stopListening()