AFNetworking和无Internet连接方案 [英] AFNetworking and No Internet Connection scenario

查看:169
本文介绍了AFNetworking和无Internet连接方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程式中为每个要求使用 AFNetworking (例如登入,从网址取得资料等)。

I use AFNetworking in my app for every request (like login, get data from url, etc).

以这个为例:用户点击登录按钮,没有连接,如何立即显示 UIAlertView ,说错误? only 方法是等待请求超时并执行失败块?是否有立即检查是否有连接的方法?

Take this for example: an user click on the login button and there's no connection, how to instantly display a UIAlertView that says the error? The only way is to wait the request timeout and execute the failure block? Isn't there a way that instantly check if there's connection or not?

谢谢!

推荐答案

从0.9开始, AFHTTPClient 实际上具有内置的网络可达性(对苹果的前述可达性代码更简单的接口)。只要包括 SystemConfiguration 框架并使用 -setReachabilityStatusChangeBlock:指定可达性状态变化时的响应。

As of 0.9, AFHTTPClient actually has network reachability built-in (a simpler interface to Apple's aforementioned Reachability code). Just include the SystemConfiguration framework and use -setReachabilityStatusChangeBlock: to specify a response when the reachability state changes.

这篇关于AFNetworking和无Internet连接方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆