IOS network monitoring-BMReachability, iosbmreachability
1. What's BMReachability?
BMReachability monitors the reachability of domains for both WWAN and WiFi network interfaces. this is a drop-in replacement for AFNetworking's Reachability class. it is ARC-compatible, and it uses the delegate methods to your y of network interface changes. it supports the use of blocks for when the network becomes reachable and unreachable. it provides monitor 2G/3G/4G network interface changes.
2. System Requirements
Requires iOS 7.0 minimum deployement version.
3. How To Use
Just # import the BMReachability. H header, add BMAddNetworkStatusObserver (self) in your code, and implement BMNetworkStatusProtocol.
Typedef NS_ENUM (NSInteger, BMNetworkReachabilityStatus ){
BMNetworkReachabilityStatusUnknown =-1,
BMNetworkReachabilityStatusNotReachable = 0,
BMNetworkReachabilityStatusReachableViaWWAN = 1,
BMNetworkReachabilityStatusReachableViaWiFi = 2,
BMNetworkReachabilityStatusReachableVia2G = 3,
BMNetworkReachabilityStatusReachableVia3G = 4,
BMNetworkReachabilityStatusReachableVia4G = 5,
};
Example:
-
(Void) dealloc {BMRemoveNetworkStatusObserver (self );}
-
(Void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [self button]; bmadnetworkdstatusobserver (self );}
-
(Void) networkStatusDidChangedFromStatus :( BMNetworkReachabilityStatus) fromStatus toStatus :( BMNetworkReachabilityStatus) toStatus {
NSLog (@"************************************ *****"); if (fromStatus! = ToStatus) {NSLog (@ "========= the status has changed ======== ");}
NSLog (@ "fromStatus: % @ toStatus: % @", @ (fromStatus), @ (toStatus ));
NSString * statusStr = [[BMEnvObserverCenterNetworkStatus defaultCenter] currentNetWorkStatusString]; NSLog (@ "current network status: % @", statusStr );
}
Warning: You must remove Network Status Observer
4. QA
Welcome to exchange, encountered problems in use, you can leave a message, of course, it is best to try to modify, have good suggestions, also hope to leave a message, or Sina Weibo contact me Sina Weibo: http://weibo.com/rubbishpicker
Github address: https://github.com/pjk1129/BMReachability
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.