added iOS source code
[wl-app.git] / iOS / Pods / GoogleUtilities / GoogleUtilities / Reachability / Private / GULReachabilityChecker.h
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
17 #import <Foundation/Foundation.h>
18 #import <SystemConfiguration/SystemConfiguration.h>
19
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
28 const NSString *GULReachabilityStatusString(GULReachabilityStatus status);
29
30 @class GULReachabilityChecker;
31
32 /// Google Analytics iOS Reachability Checker.
33 @protocol GULReachabilityDelegate
34 @required
35 /// Called when network status has changed.
36 - (void)reachability:(GULReachabilityChecker *)reachability
37        statusChanged:(GULReachabilityStatus)status;
38 @end
39
40 /// Google Analytics iOS Network Status Checker.
41 @interface GULReachabilityChecker : NSObject
42
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;
52
53 /// Initialize the reachability checker. Note that you must call start to begin checking for and
54 /// receiving notifications about network status changes.
55 ///
56 /// @param reachabilityDelegate The delegate to be notified when reachability status to host
57 /// changes.
58 ///
59 /// @param host The name of the host.
60 ///
61 - (instancetype)initWithReachabilityDelegate:(id<GULReachabilityDelegate>)reachabilityDelegate
62                                     withHost:(NSString *)host;
63
64 - (instancetype)init NS_UNAVAILABLE;
65
66 /// Start checking for reachability to the specified host. This has no effect if the status
67 /// checker is already checking for connectivity.
68 ///
69 /// @return `YES` if initiating status checking was successful or the status checking has already
70 /// been initiated, `NO` otherwise.
71 - (BOOL)start;
72
73 /// Stop checking for reachability to the specified host. This has no effect if the status
74 /// checker is not checking for connectivity.
75 - (void)stop;
76
77 @end