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. 启动mongodb和redis服务器

    一.mongodb sudo service mongod start sudo service mongod restart sudo service mongod stop 二.redis red ...

  2. Centos 添加用户和用户组

    groupadd cheat useradd -g cheat cheat passwd cheat 密码设置jsb_6041

  3. 7-nginx-keepalived配置主从双击热备

    nginx的高可用解决方案 keepalive 是 VRRP 协议的完美实现, 通过vip(虚拟ip)来实现主从双击热备, 自动切换的高可用方案, nginx的主从是通过keepalived实现的 通 ...

  4. crontab的用法

    转载于:点击打开链接   cron是一个linux下的定时执行工具,可以在无需人工干预的情况下运行作业. 由于Cron 是Linux的内置服务,但它不自动起来,可以用以下的方法启动.关闭这个服务: / ...

  5. [LeetCode]SetMatrix Zero

    题目说明 Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. c ...

  6. C++对象的内存布局以及虚函数表和虚基表

    C++对象的内存布局以及虚函数表和虚基表 本文为整理文章, 参考: http://blog.csdn.net/haoel/article/details/3081328 http://blog.csd ...

  7. yum命令速查

    1 yum的基本原理 CentOS可在yum服务器上下载官方网站给出的rpm给出的表头列表数据,该数据除了记载每个rpm软件的相依性之外,也说明了rpm所放置的容器(repository)所在.通过分 ...

  8. goldarch企业管理软件框架整体解决方案终于出来了

    所有的图片及解决方案都在我的博客里http://blog.posn.net 框架把企业管理软件开发中要遇到的常用做了组件化处理,达到了通用性和可定制性的目的. goldarch的数据层是spring. ...

  9. Oracle11g在Windows和Linux下imp导入表,exp导出表,sqluldr2导出表,sqlldr导入表

    Windows(Win10) 打开cmd 首先输入sqlplus,依次输入用户名.口令 C:\Users\hasee>sqlplus SQL*Plus: Release Production o ...

  10. Qt 绘图与动画系统

    Qt 提供了内置的绘图系统以及独立的QtOpenGL模块提供对OpenGL的支持.Qt提供了基于状态机的QPainter系统和面向对象的Graphics View系统. QPainter 基于状态机的 ...