Git Product home page Git Product logo

bmreachability's Introduction

BMReachability

What's BMReachability?

BMReachability是基于AFNetworking的Reachability类封装的监听网络状态变化的组件。 它在AF提供的无网络/wifi/蜂窝网络判断的基础上,增加了对2G/3G/4G网络的判断。

typedef NS_ENUM(NSInteger, BMNetworkReachabilityStatus) { BMNetworkReachabilityStatusUnknown = -1, BMNetworkReachabilityStatusNotReachable = 0, BMNetworkReachabilityStatusReachableViaWWAN = 1, BMNetworkReachabilityStatusReachableViaWiFi = 2, BMNetworkReachabilityStatusReachableVia2G = 3, BMNetworkReachabilityStatusReachableVia3G = 4, BMNetworkReachabilityStatusReachableVia4G = 5, };

系统要求:

最低要求支持 iOS 7.0 版本

How To Use?

在你的类中导入BMReachability.h头文件,增加BMAddNetworkStatusObserver(self)监听,并实现BMNetworkStatusProtocol,在监听对象销毁时请注意移除监听BMRemoveNetworkStatusObserver(self)

Example:

  • (void)dealloc{ BMRemoveNetworkStatusObserver(self); }
  • (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. BMAddNetworkStatusObserver(self); } #pragma mark - BMNetworkStatusProtocol
  • (void)networkStatusDidChangedFromStatus:(BMNetworkReachabilityStatus)fromStatus toStatus:(BMNetworkReachabilityStatus)toStatus{ NSLog(@"*****************************************"); if (fromStatus != toStatus) { NSLog(@"========状态改变了啊========="); } NSLog(@"fromStatus: %@ toStatus: %@",@(fromStatus),@(toStatus)); NSString *statusStr = [[BMEnvObserverCenterNetworkStatus defaultCenter] currentNetWorkStatusString]; NSLog(@"当前网络状态为: %@",statusStr);

}

特别提示: 你必须要在监听类销毁时调用BMAddNetworkStatusObserver(self);

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

Licenses

All source code is licensed under the MIT License.

bmreachability's People

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.