NetworkMonitor

public class NetworkMonitor

Use the NetworkMonitor class to determine the current status of the iOS device’s connection to the internet.

To get the type of network connection currently available, use currentNetworkConnection. If the currentNetworkConnection is WWAN, you can narrow down the type further with cellularNetworkType, which shows whether the device is using 4G, 3G, or 2G.

To subscribe to network changes, call startMonitoringNetworkChanges() and add an observer to NotificationCenter.default with NetworkMonitor.networkChangedNotificationName as the notification name. To turn off these notifications, call stopMonitoringNetworkChanges().

  • The type of cellular data network available to the iOS device. The possible values are 4G, 3G, 2G, and unknown.

    Declaration

    Swift

    public var cellularNetworkType: String?
  • Detects whether the iOS device is currently connected to the internet via WiFi or WWAN, or if there is no connection.

    Declaration

    Swift

    public var currentNetworkConnection: NetworkConnection
  • Creates a new instance of NetworkMonitor only if the current device’s network can be accessed.

    Declaration

    Swift

    public init?()