1. What ' s bmreachability?
Bmreachability is a component that monitors network state changes based on the Afnetworking reachability class. It adds an inference to the 2G/3G/4G network based on the non-network/wifi/cellular network inference provided by AF.
typedef ns_enum (Nsinteger, Bmnetworkreachabilitystatus) {
Bmnetworkreachabilitystatusunknown =-1,
bmnetworkreachabilitystatusnotreachable = 0,
Bmnetworkreachabilitystatusreachableviawwan = 1,
Bmnetworkreachabilitystatusreachableviawifi = 2,
BMNETWORKREACHABILITYSTATUSREACHABLEVIA2G = 3,
BMNETWORKREACHABILITYSTATUSREACHABLEVIA3G = 4,
BMNETWORKREACHABILITYSTATUSREACHABLEVIA4G = 5,
};
2. System Requirements:
Minimum requirements Support IOS 7.0 version number
3. How do I use?
Import the BMReachability.h header file into your class, add bmaddnetworkstatusobserver (self) listener, and implement Bmnetworkstatusprotocol, Be aware of removing listener bmremovenetworkstatusobserver (self) when listening for object destruction
Example:
-(void) dealloc{
Bmremovenetworkstatusobserver (self);
}
-(void) Viewdidload {
[Super Viewdidload];
Bmaddnetworkstatusobserver (self);
}
#pragma mark-bmnetworkstatusprotocol
-(void) Networkstatusdidchangedfromstatus: (bmnetworkreachabilitystatus) Fromstatus
Tostatus: (bmnetworkreachabilitystatus) tostatus{
NSLog (@ "*****************************************");
if (fromstatus! = tostatus) {
NSLog (@ "======== state changed AH =========");
}
NSLog (@ "Fromstatus:%@ tostatus:%@", @ (Fromstatus), @ (tostatus));
NSString *statusstr = [[Bmenvobservercenternetworkstatus defaultcenter] currentnetworkstatusstring];
NSLog (@ "Current network status:%@", STATUSSTR);
}
Special NOTE: You must call Bmaddnetworkstatusobserver (self) when the listener class is destroyed;
4. QA
Welcome to the communication, in the use of problems encountered. Can give a message, of course, it is best to try to change. Have good suggestions, also want to leave a message. Or Sina Weibo contact me Sina Weibo: Http://weibo.com/rubbishpicker
GitHub Address: Https://github.com/pjk1129/BMReachability
iOS Network monitoring-bmreachability