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宕机,怎样在第一时间监測到并通知一线运维人员进行维护,最大化降低损失. ...
随机推荐
- QLineEdit使用总结(转)
本文转自 https://www.cnblogs.com/hellovenus/p/5183593.html
- 《Linux命令行与shell脚本编程大全 第3版》Shell脚本编程基础---57
以下为阅读<Linux命令行与shell脚本编程大全 第3版>的读书笔记,为了方便记录,特地与书的内容保持同步,特意做成一节一次随笔,特记录如下:
- 浅谈密码加SALT原理(转载)
原文出处:http://www.2cto.com/Article/201201/117051.html 我们知道,如果直接对密码进行散列,那么黑客可以对通过获得这个密码散列值,然后通过查散列值字典(例 ...
- java获取当前类名和方法名
Description Below I present you two different ways to get the current Class: Using Thread Using getC ...
- 在16aspx.com上下了一个.net程序,怎么修改它的默认登录名和密码?
正常应该有个login.aspx文件,找到登入按钮事件,查看验证用户名密码事件,这个验证就有去搜索用户表,然后在这个用户表修改用户名密码就行了.不排除其他表有用用户名关联
- HDU 1171.Big Event in HDU-动态规划0-1背包
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- python 设计模式之代理模式
代理模式在一般形式上是一个类函数接口.代理可以是这些事物的接口:网络连接,存储的对象,文件,或者其他资源(昂贵的或者不容易复制的). 一个众所周知的代理模式的例子就是引用计数的指针对象. 代理模式是结 ...
- UVA 11396 Claw Decomposition 染色
原题链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- bean装配--auto
1,Dao package com.songyan.autoZhuangpei; public interface UserDao { public void say(); } package com ...
- 如何避免CSS :before、:after 中文乱码
问题: 在进行页面开发时,经常会使用:before, :after伪元素创建一些小tips,但是在:before或:after的content属性使用中文的话,会导致某些浏览器上出现乱码. 解决方案: ...