JTSReachabilit

An adaptation of Apple's Reachability with some block-based conveniences.

这是一个苹果的网络检测类的改编版本,提供便利的基于block的方法。

Usage

Usage is straightforward.

使用就如其名一样简单。

Singleton

Access the singleton instance of JTSReachabilityResponder via:

你可以通过以下方法来操作单例:

+ (instancetype)sharedInstance;

Or Non-Singleton, if You're Not Into the Whole Singleton Thing

Instantiate an instance of JTSReachabilityResponder via:

你也可以根据某个具体的hostname来作为网络检测的基准:

- (instancytype)initWithOptionalHostname:(NSString *)hostname;

If you don't specify a hostname, there are some edge cases where Apple's networking frameworks will assume there's a valid connection even when there isn't (e.g. when connected to a local WiFi network without a connection to the Internet proper).

如果你没有指定一个hostname,会有一些极端情况导致出错(比方说,你连上了路由器上的wifi,但是这个路由器没有连上网,这个时候你是不能上网的)

Registering Status Change Handlers

An object in your application registers a block to be executed whenever the network status changes between one of the three known states (none, Wi-fi, or cellular) as follows:

一个block对象会因为网络状态的改变而执行(三种状态:没有网络,wifi,cellular)

- (void)someSetupMethod {

    JTSReachabilityResponder *responder = [JTSReachabilityResponder sharedInstance];

    [responder addHandler:^(JTSNetworkStatus status) {
// Respond to the value of "status"
} forKey:@"MyReachabilityKey"];
}

Your object is responsible for cleaning up after itself, typically in dealloc, as follows:

你也需要在dealloc方法中将这个监听移除掉哦:

- (void)dealloc {

    JTSReachabilityResponder *responder = [JTSReachabilityResponder sharedInstance];

    [responder removeHandlerForKey:@"MyReachabilityKey"];
}

All blocks are called on the main thread, and must be added or removed on the main thread.

所有的block都是在主线程上面执行的,所以,也必须在主线程上面移除掉。

[翻译] JTSReachability的更多相关文章

  1. 《Django By Example》第五章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者@ucag注:大家好,我是新来的翻译, ...

  2. 《Django By Example》第四章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:祝大家新年快乐,这次带来<D ...

  3. [翻译]开发文档:android Bitmap的高效使用

    内容概述 本文内容来自开发文档"Traning > Displaying Bitmaps Efficiently",包括大尺寸Bitmap的高效加载,图片的异步加载和数据缓存 ...

  4. 【探索】机器指令翻译成 JavaScript

    前言 前些时候研究脚本混淆时,打算先学一些「程序流程」相关的概念.为了不因太枯燥而放弃,决定想一个有趣的案例,可以边探索边学. 于是想了一个话题:尝试将机器指令 1:1 翻译 成 JavaScript ...

  5. 《Django By Example》第三章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:第三章滚烫出炉,大家请不要吐槽文中 ...

  6. 《Django By Example》第二章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:翻译完第一章后,发现翻译第二章的速 ...

  7. 《Django By Example》第一章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:本人目前在杭州某家互联网公司工作, ...

  8. 【翻译】Awesome R资源大全中文版来了,全球最火的R工具包一网打尽,超过300+工具,还在等什么?

    0.前言 虽然很早就知道R被微软收购,也很早知道R在统计分析处理方面很强大,开始一直没有行动过...直到 直到12月初在微软技术大会,看到我软的工程师演示R的使用,我就震惊了,然后最近在网上到处了解和 ...

  9. ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第一章:创建基本的MVC Web站点

    在这一章中,我们将学习如何使用基架快速搭建和运行一个简单的Microsoft ASP.NET MVC Web站点.在我们马上投入学习和编码之前,我们首先了解一些有关ASP.NET MVC和Entity ...

随机推荐

  1. 在Ubuntu16.04上使用Open Grok

    Open Grok是一个强大的源代码搜索和对照引擎,是Open Solaris的源文件浏览及搜索工具.虽然Open Solaris已经不复存在,但这个工具仍然处于开发与维护之中. 相信我,绝对值得你拥 ...

  2. mysql空间扩展 VS PostGIS

    http://www.cnblogs.com/LBSer/p/3629149.html 功能 Mysql spatial extension  PostGIS 空间索引 仅MyISAM支持R树索引,I ...

  3. LeetCode【第1题】Two Sum

    准备刷一刷LeetCode了. 题目: ''' Given an array of integers, return indices of the two numbers such that they ...

  4. Nodejs学习笔记(九)—与Redis的交互(mranney/node_redis)入门

    简介和安装 redis简介: 开源高性能key-value存储:采用内存中(in-memory)数据集的方式,也可以采用磁盘存储方式(前者性能高,但数据可能丢失,后者正好相反) 支持字符串(strin ...

  5. 使用Xshell和Xftp部署简单的项目

    最近本人偶尔接触到该如何部署项目,朋友要求截图,趁此之际,简单总结一下,以供大家分享,更希望各位大神指点,大家相互学习,有问题的勿喷. 1.使用环境:win 7 + tomcat 7 + MyEcli ...

  6. hadoop学习笔记(七):Java HDFS API

    一.使用HDFS FileSystem详解 HDFS依赖的第三方包: hadoop 1.x版本: commons-configuration-1.6.jar commons-lang-2.4.jar ...

  7. 给font awesome中加入自定义图片

    工具:http://icomoon.io 在线工具 http://www.inkscape.org/en/download/windows/ 下载安装 参考教程 http://birchenough. ...

  8. MySQL 中 You can't specify target table '表名' for update in FROM clause错误解决办法

    在MySQL中,写SQL语句的时候 ,可能会遇到You can't specify target table '表名' for update in FROM clause这样的错误,它的意思是说,不能 ...

  9. Java基础教程(12)--深入理解类

    一.方法的返回值   当我们在程序中调用方法时,虚拟机将会跳转到对应的方法中去执行.当以下几种情况发生时,虚拟机将会回到调用方法的语句并继续向下执行: 执行完方法中所有的语句: 遇到return语句: ...

  10. Java中获取32位UUID

    public class createUUID { public static void main(String[] args) { String uuid = UUID.randomUUID().t ...