2 * Copyright 2017 Google
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #import <Foundation/Foundation.h>
18 #import <SystemConfiguration/SystemConfiguration.h>
20 /// Reachability Status
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;
28 const NSString *GULReachabilityStatusString(GULReachabilityStatus status);
30 @class GULReachabilityChecker;
32 /// Google Analytics iOS Reachability Checker.
33 @protocol GULReachabilityDelegate
35 /// Called when network status has changed.
36 - (void)reachability:(GULReachabilityChecker *)reachability
37 statusChanged:(GULReachabilityStatus)status;
40 /// Google Analytics iOS Network Status Checker.
41 @interface GULReachabilityChecker : NSObject
43 /// The last known reachability status, or GULReachabilityStatusUnknown if the
44 /// checker is not active.
45 @property(nonatomic, readonly) GULReachabilityStatus reachabilityStatus;
46 /// The host to which reachability status is to be checked.
47 @property(nonatomic, copy, readonly) NSString *host;
48 /// The delegate to be notified of reachability status changes.
49 @property(nonatomic, weak) id<GULReachabilityDelegate> reachabilityDelegate;
50 /// `YES` if the reachability checker is active, `NO` otherwise.
51 @property(nonatomic, readonly) BOOL isActive;
53 /// Initialize the reachability checker. Note that you must call start to begin checking for and
54 /// receiving notifications about network status changes.
56 /// @param reachabilityDelegate The delegate to be notified when reachability status to host
59 /// @param host The name of the host.
61 - (instancetype)initWithReachabilityDelegate:(id<GULReachabilityDelegate>)reachabilityDelegate
62 withHost:(NSString *)host;
64 - (instancetype)init NS_UNAVAILABLE;
66 /// Start checking for reachability to the specified host. This has no effect if the status
67 /// checker is already checking for connectivity.
69 /// @return `YES` if initiating status checking was successful or the status checking has already
70 /// been initiated, `NO` otherwise.
73 /// Stop checking for reachability to the specified host. This has no effect if the status
74 /// checker is not checking for connectivity.