[翻译] FBNetworkReachability-阿里云开发者社区

开发者社区> 安全> 正文

[翻译] FBNetworkReachability

简介:

FBNetworkReachability

 

 

 

You can use FBNetworkReachabilty class to get network reachability on iOS device.

你可以用FBNetworkReachabilty来获悉网络链接是否可用。

 

Usage

(1) Getting connection mode 下获取到网络状态值

FBNetworkReachabilityConnectionMode mode =
    [FBNetworkReachability sharedInstance].connectionMode;
switch (mode) {
    case FBNetworkReachableNon:
    break;

    case FBNetworkReachableWiFi:
    break;

    case FBNetworkReachableWWAN:
    break;
}

You can get the connection mode from 'connectionMode' property. 你也可以从connectionMode属性值中获取到网络状态

(3) Checking reachability 检测网络是否可以连上

if ([FBNetworkReachability sharedInstance].reachable) {
    :
}

You can get the rechability flag. 你可以获取到网络状态

(4) Using notification 使用通知

FBNetworkReachability posts FBNetworkReachabilityDidChangeNotification when the network reachability changs. To use the notification you can write the event driven code.

 

[[NSNotificationCenter defaultCenter]
    addObserver:self
       selector:@selector(didChangeNetworkReachability:)
           name:FBNetworkReachabilityDidChangeNotification
         object:nil];
[[FBNetworkReachability sharedInstance] startNotifier];

- (void)didChangeNetworkReachability:(NSNotification*)notification
{
    FBNetworkReachabiity* network = [notification object];
        :
}

 

Features

  • FBNetworkReachabiity does not work in background. FBNetworkReachabiity不能在后台运行
  • FBNetworkReachabiity posts the newest network rechability change. FBNetworkReachabiity会发送最新的网络修改的状态
  • The instances has same URL points to same instance internally. 
  • Thread-safe 线程安全
  • Requirements: SystemConfiguration.framework 需要使用SystemConfiguration.framework框架

 

Customize

(non)

 

Installation

You should copy below files to your projects. 添加对应的框架,然后将以下两个文件拖到你的项目中即可

FBNetworkReachability.h
FBNetworkReachability.m
SystemConfiguration.framework

 

License

see LICENSE file

 

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:
+ 订阅

云安全开发者的大本营

其他文章