使用AFNetworking 2.0设置可访问性 [英] Setting up reachability with AFNetworking 2.0

查看:123
本文介绍了使用AFNetworking 2.0设置可访问性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用新的2.0 AFNetworking 设置可达性。

I am trying to setup Reachability using the new 2.0 AFNetworking.

在我的AppDelegate中,我初始化了sharedManager。

In my AppDelegate I initialise the sharedManager.

// Instantiate Shared Manager
[AFNetworkReachabilityManager sharedManager];

然后在相关的VC方法中,我检查是否isReachable:

Then in the relevant VC method I check to see if isReachable:

// Double check with logging
if ([[AFNetworkReachabilityManager sharedManager] isReachable]) {
    NSLog(@"IS REACHABILE");
} else {
    NSLog(@"NOT REACHABLE");
}

目前这在模拟器中没有按预期工作,但我想这个需要在设备而不是模拟器上进行测试。

At present this is not working as expected in the simulator, but I imagine this would need to be tested on device and not simulator.

问题
我想要做的是监控VC。所以我在viewDidLoad中运行以下命令:

Question What I would like to do is monitor the connectivity within the VC. So I run the following in the viewDidLoad:

// Start monitoring the internet connection
[[AFNetworkReachabilityManager sharedManager] startMonitoring];

我如何注册更改?一旦网络连接发生变化,将会调用什么?我无法从文档中看到这一点。

How would I then register for the changes? What is/would be called once the network connection changes I cannot see this from the documentation.

推荐答案

正如您可以在 AFNetworking阅读我的页面

[[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
    NSLog(@"Reachability: %@", AFStringFromNetworkReachabilityStatus(status));
}];

这里也是官方文档的链接

这篇关于使用AFNetworking 2.0设置可访问性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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