Reachability.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. Copyright (C) 2014 Apple Inc. All Rights Reserved.
  3. */
  4. #import <Foundation/Foundation.h>
  5. #import <SystemConfiguration/SystemConfiguration.h>
  6. #import <netinet/in.h>
  7. typedef enum : NSInteger {
  8. NotReachable = 0,
  9. ReachableViaWiFi,
  10. ReachableViaWWAN
  11. } NetworkStatus;
  12. extern NSString *kReachabilityChangedNotification;
  13. @interface Reachability : NSObject
  14. /*!
  15. * Use to check the reachability of a given host name.
  16. */
  17. + (instancetype)reachabilityWithHostName:(NSString *)hostName;
  18. /*!
  19. * Use to check the reachability of a given IP address.
  20. */
  21. + (instancetype)reachabilityWithAddress:(const struct sockaddr_in *)hostAddress;
  22. /*!
  23. * Checks whether the default route is available. Should be used by applications that do not connect to a particular host.
  24. */
  25. + (instancetype)reachabilityForInternetConnection;
  26. /*!
  27. * Checks whether a local WiFi connection is available.
  28. */
  29. + (instancetype)reachabilityForLocalWiFi;
  30. /*!
  31. * Start listening for reachability notifications on the current run loop.
  32. */
  33. - (BOOL)startNotifier;
  34. - (void)stopNotifier;
  35. - (NetworkStatus)currentReachabilityStatus;
  36. /*!
  37. * WWAN may be available, but not active until a connection has been established. WiFi may require a connection for VPN on Demand.
  38. */
  39. - (BOOL)connectionRequired;
  40. @end