FIRReachabilityChecker.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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;
  17. @import SystemConfiguration;
  18. /// Reachability Status
  19. typedef enum {
  20. kFIRReachabilityUnknown, ///< Have not yet checked or been notified whether host is reachable.
  21. kFIRReachabilityNotReachable, ///< Host is not reachable.
  22. kFIRReachabilityViaWifi, ///< Host is reachable via Wifi.
  23. kFIRReachabilityViaCellular, ///< Host is reachable via cellular.
  24. } FIRReachabilityStatus;
  25. const NSString *FIRReachabilityStatusString(FIRReachabilityStatus status);
  26. @class FIRReachabilityChecker;
  27. @protocol FIRNetworkLoggerDelegate;
  28. /// Google Analytics iOS Reachability Checker.
  29. @protocol FIRReachabilityDelegate
  30. @required
  31. /// Called when network status has changed.
  32. - (void)reachability:(FIRReachabilityChecker *)reachability
  33. statusChanged:(FIRReachabilityStatus)status;
  34. @end
  35. /// Google Analytics iOS Network Status Checker.
  36. @interface FIRReachabilityChecker : NSObject
  37. /// The last known reachability status, or FIRReachabilityStatusUnknown if the
  38. /// checker is not active.
  39. @property(nonatomic, readonly) FIRReachabilityStatus reachabilityStatus;
  40. /// The host to which reachability status is to be checked.
  41. @property(nonatomic, copy, readonly) NSString *host;
  42. /// The delegate to be notified of reachability status changes.
  43. @property(nonatomic, weak) id<FIRReachabilityDelegate> reachabilityDelegate;
  44. /// The delegate to be notified to log messages.
  45. @property(nonatomic, weak) id<FIRNetworkLoggerDelegate> loggerDelegate;
  46. /// `YES` if the reachability checker is active, `NO` otherwise.
  47. @property(nonatomic, readonly) BOOL isActive;
  48. /// Initialize the reachability checker. Note that you must call start to begin checking for and
  49. /// receiving notifications about network status changes.
  50. ///
  51. /// @param reachabilityDelegate The delegate to be notified when reachability status to host
  52. /// changes.
  53. ///
  54. /// @param loggerDelegate The delegate to send log messages to.
  55. ///
  56. /// @param host The name of the host.
  57. ///
  58. - (instancetype)initWithReachabilityDelegate:(id<FIRReachabilityDelegate>)reachabilityDelegate
  59. loggerDelegate:(id<FIRNetworkLoggerDelegate>)loggerDelegate
  60. withHost:(NSString *)host;
  61. - (instancetype)init NS_UNAVAILABLE;
  62. /// Start checking for reachability to the specified host. This has no effect if the status
  63. /// checker is already checking for connectivity.
  64. ///
  65. /// @return `YES` if initiating status checking was successful or the status checking has already
  66. /// been initiated, `NO` otherwise.
  67. - (BOOL)start;
  68. /// Stop checking for reachability to the specified host. This has no effect if the status
  69. /// checker is not checking for connectivity.
  70. - (void)stop;
  71. @end