Afnetworkreachabilitystatus with inconsistent values when reestablishing connection

Asked

Viewed 28 times

0

I’m trying to use the Restkit framework to observe the changes in the connection through the method setReachabilityStatusChangeBlock class AFHTTPClient. As soon as the application starts I get the value AFNetworkReachabilityStatusReachableViaWiFi, and when the internet connection is disabled I get the value AFNetworkReachabilityStatusNotReachable. But when the connection is reestablished, most of the time I keep getting AFNetworkReachabilityStatusNotReachable.

1 answer

1


You’re talking about Restkit or Afnetworking?

Well, let’s have doubts.

SCNetworkReachability serves for you to monitor your network status, it can’t tell you if a host is online or offline, but it can tell if it is "Reachable", of course, if your network (not the device), can access the host.

One of the things I see around here is people using the SCNetworkReachability or Reachability (which is an abstraction of SCNetworkReachability developed by Apple), to test a network connection to then trigger a request for a remote service.

In my view, this is a total waste of time, since this way, your app takes longer to order a service and the user expects more. In addition, the network status may change in the interval between the test and the trigger of the actual request.

If in case you are using SCNetworkReachability or Reachability to test the network to then trigger a query, recommend you do the opposite, fire the query even if you have networking or not and do error handling after.

This post shows how to use this approach correctly.

In another case where you just want to, display the networking status on the screen for example, use the SCNetworkReachability or Reachability.

I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.