Permalink
Browse files

Adds Apple's reachability class with a prefix.

  • Loading branch information...
1 parent 00847d7 commit 3728081e6db06f5ee02c79724784f78439a778ec Grzegorz Adam Hankiewicz committed Jan 26, 2012
Showing with 691 additions and 0 deletions.
  1. +96 −0 Apple_ReadMe.txt
  2. +96 −0 EHReachability.h
  3. +310 −0 EHReachability.m
  4. +43 −0 README.rst
  5. +146 −0 docs/build.py
View
@@ -0,0 +1,96 @@
+Reachability
+
+========================================================================
+DESCRIPTION:
+
+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
+-applicationDidFinishLaunching.
+
+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.
+
+========================================================================
+BUILD REQUIREMENTS
+
+iOS 4.0
+
+========================================================================
+RUNTIME REQUIREMENTS
+
+iOS 4.0
+
+========================================================================
+PACKAGING LIST
+
+Reachability.h Reachability.m
+-Basic demonstration of how to use the SystemConfiguration Reachablity APIs.
+
+ReachabilityAppDelegate.h ReachabilityAppDelegate.m
+-The application's controller.
+
+========================================================================
+CHANGES FROM PREVIOUS VERSIONS
+Version 2.2
+-Updated sample for iOS 4.0
+
+Version 2.1
+-Removed [super init] from class method.
+-Fixed spelling error in method names.
+-Fixed several warnings.
+
+Version 2.0
+-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.
+
+Version 1.5
+- Updated for and tested with iPhone OS 2.0. First public release.
+
+Version 1.4
+- Updated for Beta 7.
+
+Version 1.3
+- Updated for Beta 6. - Added LSRequiresIPhoneOS key to Info.plist.
+
+Version 1.2
+- Updated for Beta 4. Added code signing.
+
+Version 1.1
+- Updated for Beta 3 to use a nib file.
+
+Copyright (C) Apple Inc. All rights reserved.
View
@@ -0,0 +1,96 @@
+/*
+
+ File: EHReachability.h
+ Abstract: Basic demonstration of how to use the SystemConfiguration Reachablity APIs.
+
+ Version: 2.2
+
+ Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
+ ("Apple") in consideration of your agreement to the following terms, and your
+ use, installation, modification or redistribution of this Apple software
+ constitutes acceptance of these terms. If you do not agree with these terms,
+ please do not use, install, modify or redistribute this Apple software.
+
+ In consideration of your agreement to abide by the following terms, and subject
+ to these terms, Apple grants you a personal, non-exclusive license, under
+ Apple's copyrights in this original Apple software (the "Apple Software"), to
+ use, reproduce, modify and redistribute the Apple Software, with or without
+ modifications, in source and/or binary forms; provided that if you redistribute
+ the Apple Software in its entirety and without modifications, you must retain
+ this notice and the following text and disclaimers in all such redistributions
+ of the Apple Software.
+ Neither the name, trademarks, service marks or logos of Apple Inc. may be used
+ to endorse or promote products derived from the Apple Software without specific
+ prior written permission from Apple. Except as expressly stated in this notice,
+ no other rights or licenses, express or implied, are granted by Apple herein,
+ including but not limited to any patent rights that may be infringed by your
+ derivative works or by other works in which the Apple Software may be
+ incorporated.
+
+ The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
+ WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
+ WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
+ COMBINATION WITH YOUR PRODUCTS.
+
+ IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
+ DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
+ CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
+ APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ Copyright (C) 2010 Apple Inc. All Rights Reserved.
+
+*/
+
+
+#import <Foundation/Foundation.h>
+#import <SystemConfiguration/SystemConfiguration.h>
+#import <netinet/in.h>
+
+
+typedef enum {
+ NotReachable = 0,
+ ReachableViaWiFi,
+ ReachableViaWWAN
+} NetworkStatus;
+#define kReachabilityChangedNotification @"kNetworkReachabilityChangedNotification"
+
+@interface EHReachability: NSObject
+{
+ BOOL localWiFiRef;
+ SCNetworkReachabilityRef reachabilityRef;
+}
+
+//reachabilityWithHostName- Use to check the reachability of a particular host name.
++ (EHReachability*) reachabilityWithHostName: (NSString*) hostName;
+
+//reachabilityWithAddress- Use to check the reachability of a particular IP address.
++ (EHReachability*) reachabilityWithAddress: (const struct sockaddr_in*) hostAddress;
+
+//reachabilityForInternetConnection- checks whether the default route is available.
+// Should be used by applications that do not connect to a particular host
++ (EHReachability*) reachabilityForInternetConnection;
+
+//reachabilityForLocalWiFi- checks whether a local wifi connection is available.
++ (EHReachability*) reachabilityForLocalWiFi;
+
+//Start listening for reachability notifications on the current run loop
+- (BOOL) startNotifier;
+- (void) stopNotifier;
+
+- (NetworkStatus) currentReachabilityStatus;
+//WWAN may be available, but not active until a connection has been established.
+//WiFi may require a connection for VPN on Demand.
+- (BOOL) connectionRequired;
+
+// Custom functions for our special use.
++ (void)init_with_host:(NSString*)hostname;
++ (EHReachability*)shared;
++ (NetworkStatus)current_status;
+
+@end
+
+
Oops, something went wrong.

0 comments on commit 3728081

Please sign in to comment.