Chapter 7. Connecting to the Network
The iOS platform is designed with always-on connectivity in mind. Developers have taken advantage of this to create some innovative third-party applications. Most iOS applications will make a network connection at some point, and many are so fundamentally tied to web services that they need a network connection to function.
Detecting Network Status
Before your application attempts to make a network connection, you need to know whether you have a network available, and depending on what you want to do, you might also want to know whether the device is connected to a WiFi or cellular network.
One of the more common reasons for Apple to reject an application submitted for review is that the application doesn’t correctly notify the user when the application fails to access the network. Apple requires that you detect the state of the network connection and report it to the user when the connection is unavailable, or otherwise handle it in a graceful manner.
Apple’s Reachability Class
Helpfully, Apple has provided some sample code to deal with detecting current network status. The Reachability code is available at http://developer.apple.com/library/ios/samplecode/Reachability/.
Two different versions of the Apple Reachability code are in general circulation. The earlier version, which appears in many web tutorials and has been widely distributed, dates from the pre-2.0 SDK. The newer version, released in August 2009, and then updated with the ...