iOS Network monitoring-bmreachability

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.