ConnectivityUtils

public struct ConnectivityUtils

A utils class to determine the connectivity status.

If you want to check the actual network status of your device manually you can do this with the help of the ConnectivityUtils class.


// This example checks the status manually inside IBActions

@IBOutlet weak var manuallyConnectivityLabel: UILabel!

@IBAction func checkMobile(_ sender: UIButton) {
   if ConnectivityUtils.isMobileConnected() {
       manuallyConnectivityLabel.text = "Mobile connected!"
   } else {
       manuallyConnectivityLabel.text = "Mobile not connected!"
   }
}

@IBAction func checkWiFi(_ sender: UIButton) {
   if ConnectivityUtils.isWiFiConnected() {
       manuallyConnectivityLabel.text = "WiFi connected!"
   } else {
       manuallyConnectivityLabel.text = "WiFi not connected!"
   }
}

@IBAction func checkOnline(_ sender: UIButton) {
   if ConnectivityUtils.isConnected() {
       manuallyConnectivityLabel.text = "Internet connected!"
   } else {
       manuallyConnectivityLabel.text = "Internet not connected!"
   }

   // or ask if a specific `ReachabilityType`is connected.
   if ConnectivityUtils.isConnected(ReachabilityType.wifi) {
       // Connected via WiFi
   }
}
  • Indicates whether there is a currently active mobile data connection that has network connectivity and data can be passed.

    Declaration

    Swift

    public static func isMobileConnected() -> Bool

    Return Value

    true if network connectivity exists, false otherwise.

  • Indicates whether there is a currently active WiFi connection that has network connectivity and data can be passed.

    Declaration

    Swift

    public static func isWiFiConnected() -> Bool

    Return Value

    true if network connectivity exists, false otherwise.

  • Indicates whether there is a currently active connection of any connectivity type that has network connectivity and data can be passed.

    Declaration

    Swift

    public static func isConnected() -> Bool

    Return Value

    true if network connectivity exists, false otherwise.

  • Indicates whether there is a currently active connection of a specific connectivity type that has network connectivity and data can be passed.

    Declaration

    Swift

    public static func isConnected(_ reachabilityType: ReachabilityType) -> Bool

    Parameters

    reachabilityType

    a reachability type as defined in ReachabilityType, such as ReachabilityType.wwan or ReachabilityType.wifi.

    Return Value

    true if network connectivity exists, false otherwise.