The Reachability sample application demonstrates how to use the System
Configuration framework to monitor the network state of an iPhone or
iPod touch. In particular, it demonstrates how to know when IP can be
routed and when traffic will be routed through a Wireless Wide Area
Network (WWAN) interface such as EDGE or 3G.
Note: Reachability cannot tell your application if you can connect to a
particular host, only that an interface is available that might allow a
connection, and whether that interface is the WWAN.
USING THE SAMPLE
Build and run the sample using Xcode. When running the iPhone Simulator,
you can exercise the application by disconnecting the Ethernet cable,
turning off AirPort, or by joining an ad-hoc local Wi-Fi network.
By default, the application uses www.apple.com for its remote host. You
can change the host it uses in ReachabilityAppDelegate.m by modifying
the call to [Reachability reachabilityWithHostName] in
IMPORTANT: Reachability must use DNS to resolve the host name before it
can determine the Reachability of that host, and this may take time on
certain network connections. Because of this, the API will return
NotReachable until name resolution has completed. This delay may be
visible in the interface on some networks.
The Reachability sample demonstrates the asynchronous use of the
SCNetworkReachability API. You can use the API synchronously, but do not
issue a synchronous check by hostName on the main thread. If the device
cannot reach a DNS server or is on a slow network, a synchronous call to
the SCNetworkReachabilityGetFlags function can block for up to 30
seconds trying to resolve the hostName. If this happens on the main
thread, the application watchdog will kill the application after 20
seconds of inactivity.
SCNetworkReachability API's do not currently provide a means to detect
support for GameKit Peer To Peer networking over BlueTooth.
-Basic demonstration of how to use the SystemConfiguration Reachablity APIs.
-The application's controller.
CHANGES FROM PREVIOUS VERSIONS
-Updated sample for iOS 4.0
-Removed [super init] from class method.
-Fixed spelling error in method names.
-Fixed several warnings.
-Greatly simplified UI code.
-Rewrote Reachability object to be fully asychronous and simplify.
monitoring of multiple SCNetworkReachabilityRefs.
-Added code showing how to monitor wether a connection will be required.
- Updated for and tested with iPhone OS 2.0. First public release.
- Updated for Beta 7.
- Updated for Beta 6. - Added LSRequiresIPhoneOS key to Info.plist.
- Updated for Beta 4. Added code signing.
- Updated for Beta 3 to use a nib file.
Copyright (C) Apple Inc. All rights reserved.
© 2010 Apple Inc. All Rights Reserved. (Last updated: 2010-07-20)