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 ofLCNetworkReachabilityManager
must be started with -startMonitoring
before reachability status can be determined.
-
The current network reachability status.
Declaration
Objective-C
@property (nonatomic, readonly) LCNetworkReachabilityStatus networkReachabilityStatus;
Swift
var networkReachabilityStatus: LCNetworkReachabilityStatus { get }
-
Whether or not the network is currently reachable.
Declaration
Objective-C
@property (nonatomic, readonly, getter=isReachable) BOOL reachable;
Swift
var isReachable: Bool { get }
-
Whether or not the network is currently reachable via WWAN.
Declaration
Objective-C
@property (nonatomic, assign, unsafe_unretained, readonly, getter=isReachableViaWWAN) BOOL reachableViaWWAN;
Swift
var isReachableViaWWAN: Bool { get }
-
Whether or not the network is currently reachable via WiFi.
Declaration
Objective-C
@property (nonatomic, assign, unsafe_unretained, readonly, getter=isReachableViaWiFi) BOOL reachableViaWiFi;
Swift
var isReachableViaWiFi: Bool { get }
-
Undocumented
Declaration
Objective-C
@property (nonatomic, strong) dispatch_queue_t reachabilityQueue
Swift
var reachabilityQueue: DispatchQueue { get set }
-
Undocumented
Declaration
Objective-C
- (LCNetworkReachabilityStatus)currentNetworkReachabilityStatus;
Swift
func currentNetworkReachabilityStatus() -> LCNetworkReachabilityStatus
-
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;
-
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()
-
Returns a localized string representation of the current network reachability status.
Declaration
Objective-C
- (nonnull NSString *)localizedNetworkReachabilityStatusString;
Swift
func localizedNetworkReachabilityStatusString() -> String
-
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 thebaseURL
.