If you write an app that uses the internet then the Apple Human Interface Guidelines require that you check for a WiFi or Wireless Wide Area Network (cellular) connection and let the user know if they are not available.
One reliable and easy way to test for this is to make use of the code in the Reachability sample project that Apple provides with XCode. Here is what you need to do:
- Add Reachability.h and Reachability.m from the sample project to your project
- Add the SystemConfiguration.framework to your project
- Use the following code in your project:
[[Reachability sharedReachability] setHostName:@"www.apple.com"];
NetworkStatus internetStatus = [[Reachability sharedReachability] remoteHostStatus];
if ((internetStatus != ReachableViaWiFiNetwork) && (internetStatus != ReachableViaCarrierDataNetwork)) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Internet Connection"
message:@"An internet connection via WiFi or cellular network is needed to use this app."
delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
} else {
// do whatever your program does
}
In the first line you can set setHostName: to whatever you like. A simple page on your server that just returns True works just fine.


That’s great and all, but being a noob, I could use a little more direction here. In step 3 you said, “add this code.” But you failed to tell us where to add that code. Does it go in the h, m, or systemconfiguration files? Also, at the end of the sample code, I could use some help telling the Reachability app what “else” to do. else die? else load app? else WHAT?
The code I provided should be placed in your implementation file (the .m one). I have been using this code in my ViewWillAppear method.
As far as what ‘else’ to do, that depends on your app. If your app connects to the internet and downloads a picture then the ‘else’ statement in my example is where you would do that. That is a super simple example of course. Basically the rest of your implementation file that you want to execute if there is an internet connection would go there.
I put the Reachability.h and Reachability.m in my Classes folder and add the SystemConfiguration.framework by right-clicking (or command-clicking) on the Frameworks folder and choosing Add->Existing Frameworks and choosing the framework.
Hope that helps clarify things.