Skip to Content

iPhone devsugar: Improved Network Reachability routines

Apple makes it clear: when applications rely on network connectivity, they must always test for a valid connection and report those results to the user. If the app cannot reach the Internet, the user needs to know. App Store reviewers regularly reject applications that do not test, and when a connection is not found, report that the network cannot be accessed.

Developers need to integrate this process into their apps. If your app connects to a server, for example, it must test the current iPhone configuration and report to the user whenever the network cannot be reached. Apple provides sample code to help with this.

iPhone developer Andrew Donoho was not particularly impressed by Apple's sample reachability code. So he decided to do something about it. He has created an open source, BSD-licensed update, which he posted on his website. His updated reachability utilities fix a few Apple misspellings and tunes up the code, allowing you to revert to the original implementation via compiler flags.

You can easily download his update and integrate it into your iPhone applications. His write-up describes the testing process and offers an implementation process for successive network tests. You build your decision tree and user feedback off the results of each test. Donoho has provided this code to allow others to build off his work without having to re-invent the entire process from Apple's original source.

If you're interested in a slightly different take on reachability, you might also want to take a peek at my UIDevice Extension category, which provides a number of other approaches to Reachability checks. Among other features, the category includes a WiFi check and hooks that allow you to change reachability status from within your application. As noted in the code, these Airplane Mode hooks are for testing only and not App Store safe.

Categories

Developer App Store SDK

Apple makes it clear: when applications rely on network connectivity, they must always test for a valid connection and report those results...
 

Add a Comment

*0 / 3000 Character Maximum

4 Comments

Filter by:
gowmukhi

Apple's code fails if there is network but the connection times out because of server is not reachable.
Any good way to handle server time outs?

December 30 2009 at 4:07 PM Report abuse rate up rate down Reply
1 reply to gowmukhi's comment
Andrew

gowmukhi,

Because the underlying Apple subsystem, SCNetworkReachability, does not actually contact the host, I'm not sure what you mean by fail. If you use + reachabilityWithHostName:, it starts off unreachable. It only becomes reachable when the DNS resolves.

December 31 2009 at 1:29 AM Report abuse rate up rate down Reply
jtb

That looks like some great code, and I can see that being really useful for many developers

December 30 2009 at 3:22 PM Report abuse rate up rate down Reply
robert

Several of the apps I use seem to forego the network-check-and-report and simply crash if there is no network. To give the developer the benefit of the doubt, they may be closing if there is no network, but it looks an awful lot like they just crash.

December 30 2009 at 3:17 PM Report abuse rate up rate down Reply
Buy an ad here

Hot Apps on TUAW

Tweets

© 2012 AOL Inc. All Rights Reserved.