码迷,mamicode.com
首页 > 移动开发 > 详细

iOS网络监控— BMReachability

时间:2015-08-09 07:18:14      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:

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 notify 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]; BMAddNetworkStatusObserver(self); }

  • (void)networkStatusDidChangedFromStatus:(BMNetworkReachabilityStatus)fromStatus toStatus:(BMNetworkReachabilityStatus)toStatus{

    NSLog(@"*****************************************"); if (fromStatus != toStatus) { NSLog(@"========状态改变了啊========="); }

    NSLog(@"fromStatus: %@ toStatus: %@",@(fromStatus),@(toStatus));

    NSString *statusStr = [[BMEnvObserverCenterNetworkStatus defaultCenter] currentNetWorkStatusString]; NSLog(@"当前网络状态为: %@",statusStr);

}

Warning: You must remove Network Status Observer

4. QA 

欢迎交流,在使用中遇到问题,可以给留言,当然最好自己试着修改,有好的建议,也希望给留言,或者新浪微博联系我 新浪微博:http://weibo.com/rubbishpicker

github地址:https://github.com/pjk1129/BMReachability

版权声明:本文为博主原创文章,未经博主允许不得转载。

iOS网络监控— BMReachability

标签:

原文地址:http://blog.csdn.net/pjk1129/article/details/47368551

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!