GULReachabilityChecker.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. #if !TARGET_OS_WATCH
  18. #import <SystemConfiguration/SystemConfiguration.h>
  19. #endif
  20. /// Reachability Status
  21. typedef enum {
  22. kGULReachabilityUnknown, ///< Have not yet checked or been notified whether host is reachable.
  23. kGULReachabilityNotReachable, ///< Host is not reachable.
  24. kGULReachabilityViaWifi, ///< Host is reachable via Wifi.
  25. kGULReachabilityViaCellular, ///< Host is reachable via cellular.
  26. } GULReachabilityStatus;
  27. const NSString *GULReachabilityStatusString(GULReachabilityStatus status);
  28. @class GULReachabilityChecker;
  29. /// Google Analytics iOS Reachability Checker.
  30. @protocol GULReachabilityDelegate
  31. @required
  32. /// Called when network status has changed.
  33. - (void)reachability:(GULReachabilityChecker *)reachability
  34. statusChanged:(GULReachabilityStatus)status;
  35. @end
  36. /// Google Analytics iOS Network Status Checker.
  37. @interface GULReachabilityChecker : NSObject
  38. /// The last known reachability status, or GULReachabilityStatusUnknown if the
  39. /// checker is not active.
  40. @property(nonatomic, readonly) GULReachabilityStatus reachabilityStatus;
  41. /// The host to which reachability status is to be checked.
  42. @property(nonatomic, copy, readonly) NSString *host;
  43. /// The delegate to be notified of reachability status changes.
  44. @property(nonatomic, weak) id<GULReachabilityDelegate> reachabilityDelegate;
  45. /// `YES` if the reachability checker is active, `NO` otherwise.
  46. @property(nonatomic, readonly) BOOL isActive;
  47. /// Initialize the reachability checker. Note that you must call start to begin checking for and
  48. /// receiving notifications about network status changes.
  49. ///
  50. /// @param reachabilityDelegate The delegate to be notified when reachability status to host
  51. /// changes.
  52. ///
  53. /// @param host The name of the host.
  54. ///
  55. - (instancetype)initWithReachabilityDelegate:(id<GULReachabilityDelegate>)reachabilityDelegate
  56. withHost:(NSString *)host;
  57. - (instancetype)init NS_UNAVAILABLE;
  58. /// Start checking for reachability to the specified host. This has no effect if the status
  59. /// checker is already checking for connectivity.
  60. ///
  61. /// @return `YES` if initiating status checking was successful or the status checking has already
  62. /// been initiated, `NO` otherwise.
  63. - (BOOL)start;
  64. /// Stop checking for reachability to the specified host. This has no effect if the status
  65. /// checker is not checking for connectivity.
  66. - (void)stop;
  67. @end