Skip to content
This repository has been archived by the owner on Oct 17, 2021. It is now read-only.

NetworkReachabilityManager

mattt edited this page Sep 18, 2020 · 2 revisions

NetworkReachabilityManager

!(os(watchOS) || os(Linux))

The NetworkReachabilityManager class 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.

Nested Type Aliases

Listener

!(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

Initializers

init?(host:​)

!(os(watchOS) || os(Linux))

Creates an instance with the specified host.

public convenience init?(host:​ String)

Parameters

  • host:​ Host used to evaluate network reachability. Must not include the scheme (e.g. https).

init?()

!(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.

Properties

`default`

!(os(watchOS) || os(Linux))

Default NetworkReachabilityManager for the zero address and a listenerQueue of .main.

let `default`

isReachable

!(os(watchOS) || os(Linux))

Whether the network is currently reachable.

var isReachable:​ Bool

isReachableOnCellular

!(os(watchOS) || os(Linux))

Whether the network is currently reachable over the cellular interface.

var isReachableOnCellular:​ Bool

isReachableOnEthernetOrWiFi

!(os(watchOS) || os(Linux))

Whether the network is currently reachable over Ethernet or WiFi interface.

var isReachableOnEthernetOrWiFi:​ Bool

reachabilityQueue

!(os(watchOS) || os(Linux))

DispatchQueue on which reachability will update.

let reachabilityQueue

flags

!(os(watchOS) || os(Linux))

Flags of the current reachability type, if any.

var flags:​ SCNetworkReachabilityFlags?

status

!(os(watchOS) || os(Linux))

The current network reachability status.

var status:​ NetworkReachabilityStatus

Methods

startListening(onQueue:​onUpdatePerforming:​)

!(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

Parameters

  • queue:​ DispatchQueue on which to call the listener closure. .main by default.
  • listener:​ Listener closure called when reachability changes.

Returns

true if listening was started successfully, false otherwise.

stopListening()

!(os(watchOS) || os(Linux))

Stops listening for changes in network reachability status.

open func stopListening()
Types
Protocols
Global Typealiases
Clone this wiki locally