[翻译] JTSReachability
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的更多相关文章
- 《Django By Example》第五章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者@ucag注:大家好,我是新来的翻译, ...
- 《Django By Example》第四章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:祝大家新年快乐,这次带来<D ...
- [翻译]开发文档:android Bitmap的高效使用
内容概述 本文内容来自开发文档"Traning > Displaying Bitmaps Efficiently",包括大尺寸Bitmap的高效加载,图片的异步加载和数据缓存 ...
- 【探索】机器指令翻译成 JavaScript
前言 前些时候研究脚本混淆时,打算先学一些「程序流程」相关的概念.为了不因太枯燥而放弃,决定想一个有趣的案例,可以边探索边学. 于是想了一个话题:尝试将机器指令 1:1 翻译 成 JavaScript ...
- 《Django By Example》第三章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:第三章滚烫出炉,大家请不要吐槽文中 ...
- 《Django By Example》第二章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:翻译完第一章后,发现翻译第二章的速 ...
- 《Django By Example》第一章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:本人目前在杭州某家互联网公司工作, ...
- 【翻译】Awesome R资源大全中文版来了,全球最火的R工具包一网打尽,超过300+工具,还在等什么?
0.前言 虽然很早就知道R被微软收购,也很早知道R在统计分析处理方面很强大,开始一直没有行动过...直到 直到12月初在微软技术大会,看到我软的工程师演示R的使用,我就震惊了,然后最近在网上到处了解和 ...
- ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第一章:创建基本的MVC Web站点
在这一章中,我们将学习如何使用基架快速搭建和运行一个简单的Microsoft ASP.NET MVC Web站点.在我们马上投入学习和编码之前,我们首先了解一些有关ASP.NET MVC和Entity ...
随机推荐
- surgemq 添加ssl
surgemq添加ssl 1.MQTT协议 消息发布订阅功能的消息队列协议 报文组成: 固定报头(控制报文类型)+可变报头(协议名称.协议级别.连接标志.保持连接)+有效载荷(clentId+will ...
- 【Express系列】第1篇——项目创建
安装 node 和 Express 4 node官网:http://nodejs.org/ Express Github:https://github.com/expressjs/express ...
- 面试题27:单链表向右旋转k个节点
Given a list, rotate the list to the right by kplaces, where k is non-negative. For example:Given1-& ...
- [C++][转]CPU字节序 网络序 主机序 大端小端
原帖:http://www.cnblogs.com/darktime/p/3298075.html 不同的CPU有不同的字节序类型 这些字节序是指整数在内存中保存的顺序 这个叫做主机序最常见的有两种1 ...
- 将AJAX Post的Data转为对应的Class
在使用DataTables从服务端获取数据时,在非MVC的情况下没有MVC的自动绑定功能,所以需要自己写一个绑定,将Post过来的InputStream转为对应的类. HTML: <form i ...
- java字符串应用之表达式解析器
一.表达式的组成 1.数字 2.运算符:+ - / * ^ % = 3.圆括号 4.变量二.运算符优先级 由高到低分别为:+-(正负号).^.*/%.+-.= 优先 ...
- 三种数据库访问——Spring JDBC
本篇随笔是上两篇的延续:三种数据库访问——原生JDBC:数据库连接池:Druid Spring的JDBC框架 Spring JDBC提供了一套JDBC抽象框架,用于简化JDBC开发. Spring主要 ...
- bootstrap 报错
1. bootstrap table 加载出错,前台报错 Cannot read property 'colspan' of undefined { title : '设备类型', field : ' ...
- [转]javascript之Object.assign()痛点
本文转自:http://blog.csdn.net/waiterwaiter/article/details/50267787 最近也一直会用javascript,然后中间使用的一些组件,如Echar ...
- 如何编写makefile文件
最近一直在学习makefile是如何编写的. 当我们写的程序文件比较少的时候,敲入gcc /g++,当你在大型工程中,在一个个编译文件的话,你可能就会很郁闷.linux有一个自带的make ...