AFNetworkReachabilityManager Class Reference
| Inherits from | NSObject |
|---|---|
| Declared in | AFNetworkReachabilityManager.h AFNetworkReachabilityManager.m |
Overview
AFNetworkReachabilityManager 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 AFNetworkReachabilityManager must be started with startMonitoring before reachability status can be determined.
Queue a status change notification for the main thread.
This is done to ensure that the notifications are received in the same order as they are sent. If notifications are sent directly, it is possible that a queued notification (for an earlier status condition) is processed after the later update, resulting in the listener being left in the wrong state.
Other Methods
networkReachabilityStatus
The current network reachability status.
@property (readonly, nonatomic, assign) AFNetworkReachabilityStatus networkReachabilityStatusDeclared In
AFNetworkReachabilityManager.h
reachable
Whether or not the network is currently reachable.
@property (readonly, nonatomic, assign, getter=isReachable) BOOL reachableDeclared In
AFNetworkReachabilityManager.h
reachableViaWWAN
Whether or not the network is currently reachable via WWAN.
@property (readonly, nonatomic, assign, getter=isReachableViaWWAN) BOOL reachableViaWWANDeclared In
AFNetworkReachabilityManager.h
reachableViaWiFi
Whether or not the network is currently reachable via WiFi.
@property (readonly, nonatomic, assign, getter=isReachableViaWiFi) BOOL reachableViaWiFiDeclared In
AFNetworkReachabilityManager.h
Initialization
+ sharedManager
Returns the shared network reachability manager.
+ (instancetype)sharedManagerDeclared In
AFNetworkReachabilityManager.h
+ manager
Creates and returns a network reachability manager with the default socket address.
+ (instancetype)managerReturn Value
An initialized network reachability manager, actively monitoring the default socket address.
Declared In
AFNetworkReachabilityManager.h
+ managerForDomain:
Creates and returns a network reachability manager for the specified domain.
+ (instancetype)managerForDomain:(NSString *)domainParameters
domain |
The domain used to evaluate network reachability. |
|---|
Return Value
An initialized network reachability manager, actively monitoring the specified domain.
Declared In
AFNetworkReachabilityManager.h
+ managerForAddress:
Creates and returns a network reachability manager for the socket address.
+ (instancetype)managerForAddress:(const void *)addressParameters
address |
The socket address ( |
|---|
Return Value
An initialized network reachability manager, actively monitoring the specified socket address.
Declared In
AFNetworkReachabilityManager.h
– initWithReachability:
Initializes an instance of a network reachability manager from the specified reachability object.
- (instancetype)initWithReachability:(SCNetworkReachabilityRef)reachabilityParameters
reachability |
The reachability object to monitor. |
|---|
Return Value
An initialized network reachability manager, actively monitoring the specified reachability.
Declared In
AFNetworkReachabilityManager.h
Starting & Stopping Reachability Monitoring
– startMonitoring
Starts monitoring for changes in network reachability status.
- (void)startMonitoringDeclared In
AFNetworkReachabilityManager.h
– stopMonitoring
Stops monitoring for changes in network reachability status.
- (void)stopMonitoringDeclared In
AFNetworkReachabilityManager.h
Getting Localized Reachability Description
– localizedNetworkReachabilityStatusString
Returns a localized string representation of the current network reachability status.
- (NSString *)localizedNetworkReachabilityStatusStringDeclared In
AFNetworkReachabilityManager.h
Setting Network Reachability Change Callback
– setReachabilityStatusChangeBlock:
Sets a callback to be executed when the network availability of the baseURL host changes.
- (void)setReachabilityStatusChangeBlock:(nullable void ( ^ ) ( AFNetworkReachabilityStatus status ))blockParameters
block |
A block object to be executed when the network availability of the |
|---|
Declared In
AFNetworkReachabilityManager.h