AFN检測网络情况
|
|
问: I'm a bit lost on AFNetorking's Reachability and haven't found a lot of good information out there. I have an app that logs into a web API. Each VC connects to the API in some way so each VC needs to have network access. I use a subclass of AFHTTPSessionManager to make network requests. I am confused as to where to put the code - is it just the appDelegate or is it in each VC? What is the use of this code?
And where do you use these methods and how do they relate to the code above?
|
答:
The -startMonitoring method of AFNetworking is used to make your start monitoring the network connection. If you do not call
AFNetworkReachabilityManager
-startMonitoring, your setReachabilityStatusChangeBlock will
never be called (regardless of where you put it) since AFNetworking isn't monitoring your connection.
As you probably assumed, -stopMonitoring does the exact opposite of
-startMonitoring - it stops the manager from checking network connectivity. I normally don't use this method in my apps, but if your app doesn't need a network connection for a certain part of it, feel free to call it (just make sure you start
monitoring the network again when you need to).
The setReachabilityStatusChangeBlock is called whenever the network status changes. You can put this wherever you want to make changes if/when the network changes. An example of this would be putting it in your app delegate and sending out a
NSNotification when the network status changes so that any view controller observing the notification can react appropriately.
You can also manually check to see if the network is online (as long as was called and AFNetworking is monitoring your network) using something like this:
-startMonitoring
if ([[AFNetworkReachabilityManager sharedManager] isReachable]) {
NSLog(@"Online");
}
You can read more on AFNetworking's official documentation on GitHub.
AFN检測网络情况的更多相关文章
- Android 检測网络是否连接
权限: <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <u ...
- iOS开发实践之网络检測Reachability
在网络应用开发中.有时须要对用户设备的网络状态进行实时监控.以至于对用户进行友好提示 或者依据不同网络状态处理不一样的逻辑(如视频播放app,依据当前的网络情况自己主动切换视频清晰度等等).用Reac ...
- android之检測是否有网络
主要是用来检測是否有网络,假设没有,就去wifi里面去进行设置网络... 以下贴一下主要代码: private void checkNetWorkInfo() { if (!Tools.isNetwo ...
- AIX下RAC搭建 Oracle10G(一)检測系统环境
AIX下RAC搭建系列 环境 节点 节点1 节点2 小机型号 IBM P-series 630 IBM P-series 630 主机名 AIX203 AIX204 交换机 SAN光纤交换机 存储 S ...
- Matlab人脸检測方法(Face Parts Detection)具体解释
今天同学让我帮忙制作一个人脸表情识别的样本库,当中主要是对人脸进行裁剪,这里用到了一个相对较新的Matlab人脸检測方法Face Parts Detection.网上百度了一下发现关于Matlab人脸 ...
- 【OpenCV新手教程之十七】OpenCV重映射 & SURF特征点检測合辑
本系列文章由@浅墨_毛星云 出品.转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/30974513 作者:毛星云(浅墨) ...
- C++内存泄露检測原理
转自:http://hi.baidu.com/jasonlyy/item/9ca0cecf2c8f113a99b4981c 本文针对 linux 下的 C++ 程序的内存泄漏的检測方法及事实上现进行探 ...
- 【OpenCV新手教程之十二】OpenCV边缘检測:Canny算子,Sobel算子,Laplace算子,Scharr滤波器合辑
本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/25560901 作者:毛星云(浅墨) ...
- server宕机监控、检測、报警程序(139绑定手机短信报警)monitor_down.sh
宕机监控报警程序 一. 需求来源 宕机对运维人员来说,最痛苦了.怎样检測一台server是否还在正常执行,假设该server宕机,怎样在第一时间监測到并通知一线运维人员进行维护,最大化降低损失. ...
随机推荐
- WCF信道绑定代码
监听端创建信道Listener,代码 using System; using System.Collections.Generic; using System.Linq; using System.T ...
- Linux中断(interrupt)子系统之五:软件中断(softIRQ)【转】
转自:http://blog.csdn.net/droidphone/article/details/7518428 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[-] 软件中 ...
- ReportView控件的使用
ReportView控件的使用Posted on 2012-01-06 17:02 随遇 阅读(3006) 评论(0) 编辑 收藏 最近使用了ReportView控件绑定数据,总结下: 1.在设计器 ...
- 树莓派3b入门教程
原文地址:传送门 这篇教程将带您一起玩转树莓派3(Raspberry Pi 3).和普通PC一样,拿到新设备第一件事就是要给它安装一个操作系统,并做一些初始化的操作.比PC简单的是,树莓派是一个固定配 ...
- (3)oracle建用户、建表、权限、命名空间
一.表空间 创建表空间 create tablespace ts001 datafile ‘d:\test\a.dbf’ size 20m uniform size 128k; 使用表空间 cre ...
- Hihocoder 1496 寻找最大值(状态压缩 + 高位前缀和)
题目链接 Hiho 1496 设$f[i]$为二进制集合包含$i$的最大的两个数,这个东西用高维前缀和维护. 高位前缀和转移的具体方案 :枚举每一位,然后枚举每个集合,大的转移到小的. 注意合并的时 ...
- codevs——1230 元素查找
时间限制: 1 s 空间限制: 128000 Ks 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description 给出n个正整数,然后有m个询问,每个询问一个整数 ...
- java copy array
13down voteaccepted Here's a java 1.4 compatible 1.5-liner: int[] array = { 1, 2, 3, 4, 5 }; int siz ...
- 两个imageView实现图片轮播
前言 在不少的项目中,都会用到图片轮播这个功能,现在网上关于图片轮播的轮子也层出不穷,千奇百怪,笔者根据自己的思路,用两个imageView也实现了图片轮播,这里给大家介绍笔者的主要思路以及大概步骤. ...
- Servlet 工作原理
Servlet运行在Servlet容器中,由容器负责Servlet实例的查找及创建工作,并按照Servlet规范的规定调用Servlet的一组方法,这些方法也叫生命周期的方法.具体调用过程如下图所示: ...