| 1 | /* |
| 2 | Copyright (C) 2016 Apple Inc. All Rights Reserved. |
| 3 | See LICENSE.txt for this sample’s licensing information |
| 4 | |
| 5 | Abstract: |
| 6 | Basic demonstration of how to use the SystemConfiguration Reachablity APIs. |
| 7 | */ |
| 8 | |
| 9 | #import <Foundation/Foundation.h> |
| 10 | #import <SystemConfiguration/SystemConfiguration.h> |
| 11 | #import <netinet/in.h> |
| 12 | |
| 13 | |
| 14 | typedef enum : NSInteger { |
| 15 | NotReachable = 0, |
| 16 | ReachableViaWiFi, |
| 17 | ReachableViaWWAN |
| 18 | } NetworkStatus; |
| 19 | |
| 20 | #pragma mark IPv6 Support |
| 21 | //Reachability fully support IPv6. For full details, see ReadMe.md. |
| 22 | |
| 23 | |
| 24 | extern NSString *kReachabilityChangedNotification; |
| 25 | |
| 26 | |
| 27 | @interface Reachability : NSObject |
| 28 | |
| 29 | /*! |
| 30 | * Use to check the reachability of a given host name. |
| 31 | */ |
| 32 | + (instancetype)reachabilityWithHostName:(NSString *)hostName; |
| 33 | |
| 34 | /*! |
| 35 | * Use to check the reachability of a given IP address. |
| 36 | */ |
| 37 | + (instancetype)reachabilityWithAddress:(const struct sockaddr *)hostAddress; |
| 38 | |
| 39 | /*! |
| 40 | * Checks whether the default route is available. Should be used by applications that do not connect to a particular host. |
| 41 | */ |
| 42 | + (instancetype)reachabilityForInternetConnection; |
| 43 | |
| 44 | |
| 45 | #pragma mark reachabilityForLocalWiFi |
| 46 | //reachabilityForLocalWiFi has been removed from the sample. See ReadMe.md for more information. |
| 47 | //+ (instancetype)reachabilityForLocalWiFi; |
| 48 | |
| 49 | /*! |
| 50 | * Start listening for reachability notifications on the current run loop. |
| 51 | */ |
| 52 | - (BOOL)startNotifier; |
| 53 | - (void)stopNotifier; |
| 54 | |
| 55 | - (NetworkStatus)currentReachabilityStatus; |
| 56 | |
| 57 | /*! |
| 58 | * WWAN may be available, but not active until a connection has been established. WiFi may require a connection for VPN on Demand. |
| 59 | */ |
| 60 | - (BOOL)connectionRequired; |
| 61 | |
| 62 | @end |
| 63 | |
| 64 |