I am using reachability from: https://github.com/tonymillion/Reachability in an objective-c app. I have it running, startNotifier is called and I see a reachabilityChanged: call when my app starts up. Now when I use the network link conditioner to simulate different network settings, I was under the assumption that reachabilityChanged: would be called.
Is that not the case or is there another step I need to do in order to simulate different network conditions? If I turn off the WiFi on my Mac, then I get reachabilityChanged: but not from doing it within network link simulator.
Reachability observes the state of the network connection, not the quality of it.
Since you are using network link conditioner you are only affecting the quality of the network like the speed or packet loss.
The only way reachability notifies you about a change is in fact when the network connection is lost or restored, as you have stated in your tests.
Related
Have a quick question on AFNetworking (2.0) Reachability Manager.
I have the code (iOS-Objective C) for checking the status of WiFi via Reachability Manager and all works fine-Good.
What happens when I have turned "ON" multiple WiFi networks in my device?
How does AFNetworking determine if WiFi is down or active?
If i am not wrong, when one WiFi network goes down, the other WiFi network will automatically be active right - i'm i making sense?
And finally, is it possible to have "AFNetworking" monitor for a specific "WiFi" network by a "WiFi Network Name" or something like that.
Cheers
I want to block my app's ui when there is no network connectivity.
I saw this post about checking network connectivity.
Is there a way to register for a listener with callback "onNetworkLost()", "onNetworkAvailable()"? Instead of creating my own periodic task?
You can use Reachability class to get notification when network status has changed. Refer https://developer.apple.com/library/ios/samplecode/Reachability/Introduction/Intro.html for documentation as well as sample code on integrating Reachability. It gives you kReachabilityChangedNotification notification which is broadcasted when network status has changed. Once you get the notification you can check whether network is available or not.
You can also refer this How to use reachability class to detect valid internet connection?
I use Stackmob SDK (which will end soon) and I assume they use AFNetworking for reachability. If a device is connected to a wifi network which is disconnected from the Internet, the reachability check will be positive and the following statement will be true:
if ([self.appDelegate.client.networkMonitor currentNetworkStatus] == SMNetworkStatusReachable) {
// reachable
}
How can I fine tune this check to overcome the present limitation? How can I check for real network reachability within this if statement, or is there any better Reachability check out there?
If your question is "can I send data to that host and receive a response", then Reachability can only answer "no" or "maybe". It cannot answer "yes" because there are many connectivity factors that Reachability does not check.
Reachability only checks the first hop. It defines reachability as the ability for packets to leave the device in the direction of that host. If the device is connected to a network that claims to be able to route to that host then Reachability is satisfied. If the router is lying or the host is down or there are unfriendly backhoes in Kansas then Reachability's result will be optimistic.
The only sure way to answer the question "can I send data to that host and receive a response" is to actually attempt to send data to that host and receive a response. Reachability can help you give up when connectivity is definitely not available. If you try and fail, Reachability's network-change notifications can help you decide when to try again without wasting power.
I want to use a messaging protocol that works fine over 3G, but not over some corporate firewalls. How can my app force the use of the cellular network when it fails to connect over WiFi even in the case that the WiFi network is reachable?
EDIT: After reading through the implementation of the Reachability class I remain unsure whether the two are indeed mutually exclusive. It could well be possible to discover both interfaces via gethostbyname(), which I might try just to see what comes out.
Use getifaddrs to enumerate the network interfaces. Look for ifa_name that starts with "pdp." This will be the cellular interface (e.g., pdp_ip0). Test (ifa_flags & IFF_UP) to make sure the interface is up, and get the IP address from ifa_addr. Then use bind() to bind your socket to that address.
Not sure how you activate the cellular interface if it is not already up. Normally, I just make a high level http call to get iOS to wake up the network, but not sure under what conditions the cellular service becomes active when wifi is also available. I suspect it is usually there as a fallback to the wifi.
http://iphonedevsdk.com/discussion/comment/120957
From the looks of that thread, it seems like its impossible. Your best bet may be to try using the protocol, and saying something like "please disconnect from wifi and retry" if it doesn't work.
This thread says just about the same thing:
how to programatically start 3g connection on iphone?
You can use the Reachability class which apple wrote in order to test whether the network connection is currently over 3G or WiFi, and even to check if a specific resource is available on the network.
You can use any of the socket library to force to use cellular. Find the cellular interface from getifaddrs, pass the interface to the socket function, socket bind will happen with cellular. e.g. CocoaAsyncSocket
G'day Guys,
I've been using the reachability API with reachability status callbacks to determine whether an application is connected over 3G or wifi. It's an application that acts as a voice extension for an existing piece of hardware and as such we're using the VoIP APIs to run in the background and accept calls etc.
Is there a definitive way other than using reachability status callbacks to determine whether you can access a particular IP endpoint or not? I could use an ASIHTTPRequest and then check if it timed out but that may cause potential problems for me in the long run.
I'm not looking for a programmatical answer but more any insights other developers would have on how to manage a roaming between the two in the background if you have a persistent connection. Basically if the device roams over to 3G I need to destroy the session on the device and if it roams back over to Wifi I need to recreate the session.
Any feedback or advice would be welcome.
The Reachability APIs will provide the connection change notifications to your app so that you can know when the connectivity changed from WWAN to wifi. It will not tell you if you've changed from Edge to 3G or LTE unfortunately. The Reachability API also has methods to test reachability to a specific host. So, in your app you can listen for the notifications that the connection method has changed, then when it does change test reachability to your target host and at that time make the decision whether to rebuild the session or leave it intact.