LCNetworkReachabilityManager

Objective-C

@interface LCNetworkReachabilityManager : NSObject

Swift

class LCNetworkReachabilityManager : NSObject

LCNetworkReachabilityManager monitors the reachability of domains, and addresses for both WWAN and WiFi network interfaces.

Reachability can be used to determine background information about why a network operation failed, or to trigger a network operation retrying 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.

See Apple’s Reachability Sample Code ( https://developer.apple.com/library/ios/samplecode/reachability/ )

Warning

Instances of LCNetworkReachabilityManager must be started with -startMonitoring before reachability status can be determined.

Initialization

  • Returns the shared network reachability manager.

    Declaration

    Objective-C

    + (nonnull instancetype)sharedManager;

    Swift

    class func shared() -> Self
  • Creates and returns a network reachability manager with the default socket address.

    Declaration

    Objective-C

    + (nonnull instancetype)manager;

    Return Value

    An initialized network reachability manager, actively monitoring the default socket address.

  • Creates and returns a network reachability manager for the specified domain.

    Declaration

    Objective-C

    + (nonnull instancetype)managerForDomain:(nonnull NSString *)domain;

    Swift

    convenience init(forDomain domain: String)

    Parameters

    domain

    The domain used to evaluate network reachability.

    Return Value

    An initialized network reachability manager, actively monitoring the specified domain.

  • Creates and returns a network reachability manager for the socket address.

    Declaration

    Objective-C

    + (nonnull instancetype)managerForAddress:(nonnull const void *)address;

    Swift

    convenience init(forAddress address: UnsafeRawPointer)

    Parameters

    address

    The socket address (sockaddr_in6) used to evaluate network reachability.

    Return Value

    An initialized network reachability manager, actively monitoring the specified socket address.

  • Initializes an instance of a network reachability manager from the specified reachability object.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithReachability:
        (nonnull SCNetworkReachabilityRef)reachability;

    Swift

    init(reachability: SCNetworkReachability)

    Parameters

    reachability

    The reachability object to monitor.

    Return Value

    An initialized network reachability manager, actively monitoring the specified reachability.

  • Unavailable

    Unavailable initializer

    Declaration

    Objective-C

    + (nonnull instancetype)new;
  • Unavailable

    Unavailable initializer

    Declaration

    Objective-C

    - (nonnull instancetype)init;

Starting & Stopping Reachability Monitoring

  • Starts monitoring for changes in network reachability status.

    Declaration

    Objective-C

    - (void)startMonitoring;

    Swift

    func startMonitoring()
  • Stops monitoring for changes in network reachability status.

    Declaration

    Objective-C

    - (void)stopMonitoring;

    Swift

    func stopMonitoring()

Getting Localized Reachability Description

  • Returns a localized string representation of the current network reachability status.

    Declaration

    Objective-C

    - (nonnull NSString *)localizedNetworkReachabilityStatusString;

    Swift

    func localizedNetworkReachabilityStatusString() -> String

Setting Network Reachability Change Callback

  • Sets a callback to be executed when the network availability of the baseURL host changes.

    Declaration

    Objective-C

    - (void)setReachabilityStatusChangeBlock:
        (nullable void (^)(LCNetworkReachabilityStatus))block;

    Swift

    func setReachabilityStatusChange(_ block: ((LCNetworkReachabilityStatus) -> Void)?)

    Parameters

    block

    A block object to be executed when the network availability of the baseURL host changes.. This block has no return value and takes a single argument which represents the various reachability states from the device to the baseURL.