docs/docsets/Alamofire.docset/Contents/Resources/Documents/Classes/NetworkReachabilityManager.html
@available(macOS, deprecated: 14.4, message: "Use NWPathMonitor instead.")
@available(iOS, deprecated: 17.4, message: "Use NWPathMonitor instead.")
@available(watchOS, deprecated: 9.4, message: "Use NWPathMonitor instead.")
@available(tvOS, deprecated: 17.4, message: "Use NWPathMonitor instead.")
@available(visionOS, deprecated: 1.4, message: "Use NWPathMonitor instead.")
open class NetworkReachabilityManager : @unchecked Sendable
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.
`
NetworkReachabilityStatus
`
Defines the various states of network reachability.
Swift
public enum NetworkReachabilityStatus : Equatable, Sendable
`
Listener
`
A closure executed when the network reachability status changes. The closure takes a single argument: the network reachability status.
Swift
public typealias Listener = @Sendable (NetworkReachabilityStatus) -> Void
`
default
`
Default NetworkReachabilityManager for the zero address and a listenerQueue of .main.
Swift
public static let `default`: NetworkReachabilityManager?
`
isReachable
`
Whether the network is currently reachable.
Swift
open var isReachable: Bool { get }
`
isReachableOnCellular
`
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 the allowsCellularAccess on any URLRequests being issued.
Swift
open var isReachableOnCellular: Bool { get }
`
isReachableOnEthernetOrWiFi
`
Whether the network is currently reachable over Ethernet or WiFi interface.
Swift
open var isReachableOnEthernetOrWiFi: Bool { get }
`
reachabilityQueue
`
DispatchQueue on which reachability will update.
Swift
public let reachabilityQueue: DispatchQueue
`
flags
`
Flags of the current reachability type, if any.
Swift
open var flags: SCNetworkReachabilityFlags? { get }
`
status
`
The current network reachability status.
Swift
open var status: NetworkReachabilityStatus { get }
`
init(host:)
`
Creates an instance with the specified host.
Note
The host value must not contain a scheme, just the hostname.
Swift
public convenience init?(host: String)
| host |
Host used to evaluate network reachability. Must not include the scheme (e.g. https).
|
`
init()
`
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.
Swift
public convenience init?()
`
startListening(onQueue:onUpdatePerforming:)
`
Starts listening for changes in network reachability status.
Note
Stops and removes any existing listener.
Swift
@discardableResult
@preconcurrency
open func startListening(onQueue queue: DispatchQueue = .main,
onUpdatePerforming listener: @escaping Listener) -> Bool
| queue |
DispatchQueue on which to call the listener closure. .main by default.
|
| listener |
Listener closure called when reachability changes.
|
true if listening was started successfully, false otherwise.
`
stopListening()
`
Stops listening for changes in network reachability status.
Swift
open func stopListening()