Reachability.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. File: Reachability.h
  3. Abstract: Basic demonstration of how to use the SystemConfiguration Reachablity APIs.
  4. Version: 2.2
  5. Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
  6. ("Apple") in consideration of your agreement to the following terms, and your
  7. use, installation, modification or redistribution of this Apple software
  8. constitutes acceptance of these terms. If you do not agree with these terms,
  9. please do not use, install, modify or redistribute this Apple software.
  10. In consideration of your agreement to abide by the following terms, and subject
  11. to these terms, Apple grants you a personal, non-exclusive license, under
  12. Apple's copyrights in this original Apple software (the "Apple Software"), to
  13. use, reproduce, modify and redistribute the Apple Software, with or without
  14. modifications, in source and/or binary forms; provided that if you redistribute
  15. the Apple Software in its entirety and without modifications, you must retain
  16. this notice and the following text and disclaimers in all such redistributions
  17. of the Apple Software.
  18. Neither the name, trademarks, service marks or logos of Apple Inc. may be used
  19. to endorse or promote products derived from the Apple Software without specific
  20. prior written permission from Apple. Except as expressly stated in this notice,
  21. no other rights or licenses, express or implied, are granted by Apple herein,
  22. including but not limited to any patent rights that may be infringed by your
  23. derivative works or by other works in which the Apple Software may be
  24. incorporated.
  25. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
  26. WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
  27. WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28. PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
  29. COMBINATION WITH YOUR PRODUCTS.
  30. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
  31. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  32. GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33. ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
  34. DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
  35. CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
  36. APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. Copyright (C) 2010 Apple Inc. All Rights Reserved.
  38. */
  39. #import <SystemConfiguration/SystemConfiguration.h>
  40. #import <netinet/in.h>
  41. typedef enum {
  42. NotReachable = 0,
  43. ReachableViaWiFi,
  44. ReachableViaWWAN
  45. } NetworkStatus;
  46. #define kReachabilityChangedNotification @"kNetworkReachabilityChangedNotification"
  47. @interface Reachability: NSObject
  48. {
  49. BOOL localWiFiRef;
  50. SCNetworkReachabilityRef reachabilityRef;
  51. }
  52. //reachabilityWithHostName- Use to check the reachability of a particular host name.
  53. + (Reachability*) reachabilityWithHostName: (NSString*) hostName;
  54. //reachabilityWithAddress- Use to check the reachability of a particular IP address.
  55. + (Reachability*) reachabilityWithAddress: (const struct sockaddr_in*) hostAddress;
  56. //reachabilityForInternetConnection- checks whether the default route is available.
  57. // Should be used by applications that do not connect to a particular host
  58. + (Reachability*) reachabilityForInternetConnection;
  59. //reachabilityForLocalWiFi- checks whether a local wifi connection is available.
  60. + (Reachability*) reachabilityForLocalWiFi;
  61. //Start listening for reachability notifications on the current run loop
  62. - (BOOL) startNotifier;
  63. - (void) stopNotifier;
  64. - (NetworkStatus) currentReachabilityStatus;
  65. //WWAN may be available, but not active until a connection has been established.
  66. //WiFi may require a connection for VPN on Demand.
  67. - (BOOL) connectionRequired;
  68. @end