[翻译] 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 ...
随机推荐
- alloca() 是什么?为什么不提倡使用它?
在调用 alloca() 的函数返回的时候, 它分配的内存会自动释放.也就是说, 用 alloca 分配的内存在某种程度上局部于函数的 ``堆栈帧" 或上下文中. alloca() 不具可 ...
- InnoSetup打包时出现Interal error: CallSpawnServer: Unexpected response: $0.错误的解决办法
如果在使用Innosetup打包软件时,如果出现Interal error: CallSpawnServer: Unexpected response: $0.错误, 如下图: 可以查看 Innose ...
- JAVA GUID
import java.util.UUID; import java.util.concurrent.ExecutorService; import java.util.concurrent.Exec ...
- 学习ThinkPHP笔记
学习ThinkPHP笔记 TP的模块化设计 名称 描述 应用 基于同一个入口文件访问的项目我们称之为一个应用. 模块 一个应用下面可以包含多个模块,每个模块在应用目录下面都是一个独立的子目录. 控制器 ...
- [codeup] 2044 神奇的口袋
题目描述 有一个神奇的口袋,总的容积是40,用这个口袋可以变出一些物品,这些物品的总体积必须是40.John现在有n个想要得到的物品,每个物品的体积分别是a1,a2--an.John可以从这些物品中选 ...
- template-web.js 真分页绑定表格
<div class="layui-table-box"> <div class="layui-tabl ...
- QQ简易版
package QQ; /* * * 登录界面 * */ import javax.swing.*; import java.awt.event.ActionEvent; import java.aw ...
- SpringBean 工作原理详解
本文来自Github开源项目https://github.com/Snailclimb/JavaGuide,只供自己学习总结无商业用途,如有侵权,联系删除 前言 在 Spring 中,那些组成应用程序 ...
- php初学记
开始和结束标记 常用两种:<?php ?>,<script language="php"></script> 短标记:<? ?>,需 ...
- Google JavaScript样式指南
Google JavaScript样式指南 目录 1简介 1.1术语说明 1.2指南说明 2源文件基础知识 2.1文件名 2.2文件编码:UTF-8 2.3特殊字符 3源文件结构 3.1许可或版权 ...