ConnectivityReceiver

public class ConnectivityReceiver

The ConnectivityReceiver informs all registered ConnectivityObservers about connectivity type changes.

To use the ConnectivityReceiver you have to implement the ConnectivityObserver protocol in your class and implement the given functions.

// register observer to start the Monitoring
ConnectivityReceiver.registerObserver(self)

// MARK: Protocol Functions
func connectionEstablished() {
   logger.debug("Connection established")
   // do something useful
}

func connectionChanged(_ previousReachabilityType: ReachabilityType, reachabilityType: ReachabilityType) {
   logger.debug("connection changed")
   // do something useful
}

func connectionLost() {
   logger.debug("Connection lost")
   // do something useful
}

You always should unregister your observers to prevent memory leaks.

// unregister observer, if observer list is empty the monitoring stops
ConnectivityReceiver.unregisterObserver(self)
  • Array of registered observers that are to be informed about connectivity type changes.

    Note

    Observers have to be removed - that is, unregistered to prevent memory leaks once they are not supposed to be called anymore.

    Declaration

    Swift

    public static var observers: [ConnectivityObserver]
  • Adds the observer to the array of registered ConnectivityObservers. All registered observers are called every time the device’s connectivity type changes.

    Declaration

    Swift

    public static func registerObserver(_ observer: ConnectivityObserver)

    Parameters

    observer
  • Removes the observer from the array of registered ConnectivityObservers. The observer will no longer be informed about connectivity type changes.

    Declaration

    Swift

    public static func unregisterObserver(_ observer: ConnectivityObserver)

    Parameters

    observer