MBNetworkMonitor Class Reference

Inherits from NSObject
Conforms to MBService
Declared in MBNetworkMonitor.h

Overview

Provides a mechanism for determining network availability and requesting updates about network status changes.

You can use this singleton to query the current network availability.

The MBNetworkMonitor class also acts as a service that, when running, will post the following NSNotificationCenter events when the status of the network changes:

  • MBNetwork:didGoOnline — Indicates that the network has become available. This is also fired immediately if the network is available when the service starts.

  • MBNetwork:didGoOffline — Indicates that the network went offline. Sending network requests will fail when offline.

  • MBNetwork:wifiConnected — Indicates that a network connection became available through wifi.

  • MBNetwork:wifiDisconnected — Indicates that the wifi network connection is no longer available. A connection may still be available through a wireless carrier.

  • MBNetwork:carrierConnectionChanged — Indicates that the state of the carrier network connection changed.

Note: By default, changes in network status do not result in events being fired. Notification events are posted only when the MBNetworkMonitor service is running. If the network status needs to be checked repeatedly, it is more efficient to utilize the event-based mechanism provided by the service. Use the interface provided by the MBServiceManager to ensure that the service is running when needed.

Querying network status

  isOnline

Indicates whether a network is currently available to the device. If called repeatedly, it is more efficient to have the service running to avoid querying SCNetworkReachabilityGetFlags directly.

@property (nonatomic, assign, readonly) BOOL isOnline

Declared In

MBNetworkMonitor.h

  isWifiConnected

Indicates whether the network connection (if any) is via wifi. If called repeatedly, it is more efficient to have the service running to avoid querying SCNetworkReachabilityGetFlags directly.

@property (nonatomic, assign, readonly) BOOL isWifiConnected

Declared In

MBNetworkMonitor.h

  hasCellularCarrier

Determines whether the device currently has an associated cellular carrier.

@property (nonatomic, readonly) BOOL hasCellularCarrier

Declared In

MBNetworkMonitor.h

  cellularCarrierName

Returns the name of the cellular carrier currently associated with the device.

@property (nullable, nonatomic, readonly) NSString *cellularCarrierName

Declared In

MBNetworkMonitor.h

  cellularCarrierCountry

Returns the ISO country code of the cellular carrier currently associated with the device.

@property (nullable, nonatomic, readonly) NSString *cellularCarrierCountry

Declared In

MBNetworkMonitor.h

  cellularConnectionType

Returns a string identifying the type of cellular connection currently in use by the device.

@property (nullable, nonatomic, readonly) NSString *cellularConnectionType

Declared In

MBNetworkMonitor.h

  carrierStatusDescription

Returns a human-readable string describing the current state of the cellular carrier connection. Returns the constant kMBNetworkNoCarrierStatusDescription when the hasCellularCarrier property would return NO.

@property (nonnull, nonatomic, readonly) NSString *carrierStatusDescription

Declared In

MBNetworkMonitor.h

  networkAvailability

Indicates the current status of network availability by querying SCNetworkReachabilityGetFlags directly. Not very processor-efficient for repeated use; it’s better to turn on the service and rely on the event-based mechanism.

@property (nonatomic, assign, readonly) MBNetworkAvailabilityFlags networkAvailability

Declared In

MBNetworkMonitor.h

  networkAvailabilityDescription

Returns a string describing the current networkAvailability property in human-readable form.

@property (nonnull, nonatomic, readonly) NSString *networkAvailabilityDescription

Declared In

MBNetworkMonitor.h

  reachabilityFlagsDescription

Returns the SCNetworkReachabilityFlags in a human-readable string form. Intended for use with debugging possible connectivity problems.

@property (nullable, nonatomic, readonly) NSString *reachabilityFlagsDescription

Declared In

MBNetworkMonitor.h