IOS network monitoring-BMReachability, iosbmreachability

Source: Internet
Author: User

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.

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.