TDSReachability.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // XDReachability.h
  3. // TDS
  4. //
  5. // Created by JiangJiahao on 2019/7/25.
  6. // Copyright © 2019 X.D. Network Inc. All rights reserved.
  7. // 直接用的YYReachability
  8. #import <Foundation/Foundation.h>
  9. #import <SystemConfiguration/SystemConfiguration.h>
  10. #import <netinet/in.h>
  11. NS_ASSUME_NONNULL_BEGIN
  12. typedef NS_ENUM(NSUInteger, TDSReachabilityStatus) {
  13. TDSReachabilityStatusNone = 0, ///< Not Reachable
  14. TDSReachabilityStatusWWAN = 1, ///< Reachable via WWAN (2G/3G/4G)
  15. TDSReachabilityStatusWiFi = 2, ///< Reachable via WiFi
  16. };
  17. typedef NS_ENUM(NSUInteger, TDSReachabilityWWANStatus) {
  18. TDSReachabilityWWANStatusNone = 0, ///< Not Reachable vis WWAN
  19. TDSReachabilityWWANStatus2G = 2, ///< Reachable via 2G (GPRS/EDGE) 10~100Kbps
  20. TDSReachabilityWWANStatus3G = 3, ///< Reachable via 3G (WCDMA/HSDPA/...) 1~10Mbps
  21. TDSReachabilityWWANStatus4G = 4, ///< Reachable via 4G (eHRPD/LTE) 100Mbps
  22. TDSReachabilityWWANStatus5G = 5, ///< Reachable via 5G (sa/nsa) 500Mbps
  23. };
  24. @interface TDSReachability : NSObject
  25. @property (nonatomic, readonly) SCNetworkReachabilityFlags flags; ///< Current flags.
  26. @property (nonatomic, readonly) TDSReachabilityStatus status; ///< Current status.
  27. @property (nonatomic, readonly) TDSReachabilityWWANStatus wwanStatus NS_AVAILABLE_IOS(7_0); ///< Current WWAN status.
  28. @property (nonatomic, readonly, getter=isReachable) BOOL reachable; ///< Current reachable status.
  29. /// Notify block which will be called on main thread when network changed.
  30. @property (nullable, nonatomic, copy) void (^TDSReachabilityNotifyBlock)(TDSReachability *reachability);
  31. /// Create an object to check the reachability of the default route.
  32. + (instancetype)reachability;
  33. /// Create an object to check the reachability of the local WI-FI.
  34. + (instancetype)reachabilityForLocalWifi DEPRECATED_MSG_ATTRIBUTE("unnecessary and potentially harmful");
  35. /// Create an object to check the reachability of a given host name.
  36. + (nullable instancetype)reachabilityWithHostname:(NSString *)hostname;
  37. /// Create an object to check the reachability of a given IP address
  38. /// @param hostAddress You may pass `struct sockaddr_in` for IPv4 address or `struct sockaddr_in6` for IPv6 address.
  39. + (nullable instancetype)reachabilityWithAddress:(const struct sockaddr *)hostAddress;
  40. @end
  41. NS_ASSUME_NONNULL_END