Afnetworking 2.0 Reachability

AFNetworking 2.0 Reachability

That's because that block is only executed when reachability changes.

To get the current status, you can do this:

- (BOOL)connected {
return [AFNetworkReachabilityManager sharedManager].reachable;
}

Setting up reachability with AFNetworking 2.0

As you can read in the AFNetworking read me page

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

Here's also a link to the official documentation.

AFNetworking 2.0 Reachability not working

I needed to start the reachability monitor.

[self.manager.reachabilityManager startMonitoring]; 

I find it by accident, documentation should state this in my opinion.

AFNetworking reachability status not changing

This is because a 100% loss situation isn't equal to doesn't have a connection at all. 100% loss means that all of the packets are dropped but the network connection still exists, it is usefull when you want to simulate a timeout connection.

In order to simulate the no network case you should turn your wifi connection off on your mac or iDevice, for simulator or physical device.

Monitoring Reachability with AFNetworking only on a presented controller

Unfortunately no, there isn't an easier way to do this.

However, the plan you mentioned doesn't sound all that bad. You essentially are asking the manager to turn it's notifications off and on, and it needs you to tell it when to do so.

Here's how I do it:

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[manager startMonitoring];
}

- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[manager stopMonitoring];
}


Related Topics



Leave a reply



Submit