1 |
efrain |
1 |
/*
|
|
|
2 |
* Copyright 2019 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 |
|
|
|
19 |
#if !TARGET_OS_WATCH
|
|
|
20 |
#import <SystemConfiguration/SystemConfiguration.h>
|
|
|
21 |
#endif
|
|
|
22 |
|
|
|
23 |
#if TARGET_OS_IOS || TARGET_OS_TV
|
|
|
24 |
#import <UIKit/UIKit.h>
|
|
|
25 |
#elif TARGET_OS_OSX
|
|
|
26 |
#import <AppKit/AppKit.h>
|
|
|
27 |
#elif TARGET_OS_WATCH
|
|
|
28 |
#import <WatchKit/WatchKit.h>
|
|
|
29 |
#endif // TARGET_OS_IOS || TARGET_OS_TV
|
|
|
30 |
|
|
|
31 |
#if TARGET_OS_IOS
|
|
|
32 |
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
|
|
|
33 |
#endif
|
|
|
34 |
|
|
|
35 |
NS_ASSUME_NONNULL_BEGIN
|
|
|
36 |
|
|
|
37 |
/** The GoogleDataTransport library version. */
|
|
|
38 |
FOUNDATION_EXPORT NSString *const kGDTCORVersion;
|
|
|
39 |
|
|
|
40 |
/** A notification sent out if the app is backgrounding. */
|
|
|
41 |
FOUNDATION_EXPORT NSString *const kGDTCORApplicationDidEnterBackgroundNotification;
|
|
|
42 |
|
|
|
43 |
/** A notification sent out if the app is foregrounding. */
|
|
|
44 |
FOUNDATION_EXPORT NSString *const kGDTCORApplicationWillEnterForegroundNotification;
|
|
|
45 |
|
|
|
46 |
/** A notification sent out if the app is terminating. */
|
|
|
47 |
FOUNDATION_EXPORT NSString *const kGDTCORApplicationWillTerminateNotification;
|
|
|
48 |
|
|
|
49 |
/** The different possible network connection type. */
|
|
|
50 |
typedef NS_ENUM(NSInteger, GDTCORNetworkType) {
|
|
|
51 |
GDTCORNetworkTypeUNKNOWN = 0,
|
|
|
52 |
GDTCORNetworkTypeWIFI = 1,
|
|
|
53 |
GDTCORNetworkTypeMobile = 2,
|
|
|
54 |
};
|
|
|
55 |
|
|
|
56 |
/** The different possible network connection mobile subtype. */
|
|
|
57 |
typedef NS_ENUM(NSInteger, GDTCORNetworkMobileSubtype) {
|
|
|
58 |
GDTCORNetworkMobileSubtypeUNKNOWN = 0,
|
|
|
59 |
GDTCORNetworkMobileSubtypeGPRS = 1,
|
|
|
60 |
GDTCORNetworkMobileSubtypeEdge = 2,
|
|
|
61 |
GDTCORNetworkMobileSubtypeWCDMA = 3,
|
|
|
62 |
GDTCORNetworkMobileSubtypeHSDPA = 4,
|
|
|
63 |
GDTCORNetworkMobileSubtypeHSUPA = 5,
|
|
|
64 |
GDTCORNetworkMobileSubtypeCDMA1x = 6,
|
|
|
65 |
GDTCORNetworkMobileSubtypeCDMAEVDORev0 = 7,
|
|
|
66 |
GDTCORNetworkMobileSubtypeCDMAEVDORevA = 8,
|
|
|
67 |
GDTCORNetworkMobileSubtypeCDMAEVDORevB = 9,
|
|
|
68 |
GDTCORNetworkMobileSubtypeHRPD = 10,
|
|
|
69 |
GDTCORNetworkMobileSubtypeLTE = 11,
|
|
|
70 |
};
|
|
|
71 |
|
|
|
72 |
#if !TARGET_OS_WATCH
|
|
|
73 |
/** Define SCNetworkReachabilityFlags as GDTCORNetworkReachabilityFlags on non-watchOS. */
|
|
|
74 |
typedef SCNetworkReachabilityFlags GDTCORNetworkReachabilityFlags;
|
|
|
75 |
|
|
|
76 |
/** Define SCNetworkReachabilityRef as GDTCORNetworkReachabilityRef on non-watchOS. */
|
|
|
77 |
typedef SCNetworkReachabilityRef GDTCORNetworkReachabilityRef;
|
|
|
78 |
|
|
|
79 |
#else
|
|
|
80 |
/** The different possible reachabilityFlags option on watchOS. */
|
|
|
81 |
typedef NS_OPTIONS(uint32_t, GDTCORNetworkReachabilityFlags) {
|
|
|
82 |
kGDTCORNetworkReachabilityFlagsReachable = 1 << 1,
|
|
|
83 |
// TODO(doudounan): Add more options on watchOS if watchOS network connection information relative
|
|
|
84 |
// APIs available in the future.
|
|
|
85 |
};
|
|
|
86 |
|
|
|
87 |
/** Define a struct as GDTCORNetworkReachabilityRef on watchOS to store network connection
|
|
|
88 |
* information. */
|
|
|
89 |
typedef struct {
|
|
|
90 |
// TODO(doudounan): Store network connection information on watchOS if watchOS network connection
|
|
|
91 |
// information relative APIs available in the future.
|
|
|
92 |
} GDTCORNetworkReachabilityRef;
|
|
|
93 |
#endif
|
|
|
94 |
|
|
|
95 |
/** Returns a URL to the root directory under which all GDT-associated data must be saved.
|
|
|
96 |
*
|
|
|
97 |
* @return A URL to the root directory under which all GDT-associated data must be saved.
|
|
|
98 |
*/
|
|
|
99 |
NSURL *GDTCORRootDirectory(void);
|
|
|
100 |
|
|
|
101 |
/** Compares flags with the reachable flag (on non-watchos with both reachable and
|
|
|
102 |
* connectionRequired flags), if available, and returns YES if network reachable.
|
|
|
103 |
*
|
|
|
104 |
* @param flags The set of reachability flags.
|
|
|
105 |
* @return YES if the network is reachable, NO otherwise.
|
|
|
106 |
*/
|
|
|
107 |
BOOL GDTCORReachabilityFlagsReachable(GDTCORNetworkReachabilityFlags flags);
|
|
|
108 |
|
|
|
109 |
/** Compares flags with the WWAN reachability flag, if available, and returns YES if present.
|
|
|
110 |
*
|
|
|
111 |
* @param flags The set of reachability flags.
|
|
|
112 |
* @return YES if the WWAN flag is set, NO otherwise.
|
|
|
113 |
*/
|
|
|
114 |
BOOL GDTCORReachabilityFlagsContainWWAN(GDTCORNetworkReachabilityFlags flags);
|
|
|
115 |
|
|
|
116 |
/** Generates an enum message GDTCORNetworkType representing network connection type.
|
|
|
117 |
*
|
|
|
118 |
* @return A GDTCORNetworkType representing network connection type.
|
|
|
119 |
*/
|
|
|
120 |
GDTCORNetworkType GDTCORNetworkTypeMessage(void);
|
|
|
121 |
|
|
|
122 |
/** Generates an enum message GDTCORNetworkMobileSubtype representing network connection mobile
|
|
|
123 |
* subtype.
|
|
|
124 |
*
|
|
|
125 |
* @return A GDTCORNetworkMobileSubtype representing network connection mobile subtype.
|
|
|
126 |
*/
|
|
|
127 |
GDTCORNetworkMobileSubtype GDTCORNetworkMobileSubTypeMessage(void);
|
|
|
128 |
|
|
|
129 |
/** Identifies the model of the device on which the library is currently working on.
|
|
|
130 |
*
|
|
|
131 |
* @return A NSString representing the device model.
|
|
|
132 |
*/
|
|
|
133 |
NSString *_Nonnull GDTCORDeviceModel(void);
|
|
|
134 |
|
|
|
135 |
/** Writes the given object to the given fileURL and populates the given error if it fails.
|
|
|
136 |
*
|
|
|
137 |
* @param obj The object to encode.
|
|
|
138 |
* @param filePath The path to write the object to. Can be nil if you just need the data.
|
|
|
139 |
* @param error The error to populate if something goes wrong.
|
|
|
140 |
* @return The data of the archive. If error is nil, it's been written to disk.
|
|
|
141 |
*/
|
|
|
142 |
NSData *_Nullable GDTCOREncodeArchive(id<NSSecureCoding> obj,
|
|
|
143 |
NSString *_Nullable filePath,
|
|
|
144 |
NSError *_Nullable *error);
|
|
|
145 |
|
|
|
146 |
/** Decodes an object of the given class from the given archive path or data and populates the given
|
|
|
147 |
* error if it fails.
|
|
|
148 |
*
|
|
|
149 |
* @param archiveClass The class of the archive's root object.
|
|
|
150 |
* @param archivePath The path to the archived data. Don't use with the archiveData param.
|
|
|
151 |
* @param archiveData The data to decode. Don't use with the archivePath param.
|
|
|
152 |
* @param error The error to populate if something goes wrong.
|
|
|
153 |
*/
|
|
|
154 |
id<NSSecureCoding> _Nullable GDTCORDecodeArchive(Class archiveClass,
|
|
|
155 |
NSString *_Nullable archivePath,
|
|
|
156 |
NSData *_Nullable archiveData,
|
|
|
157 |
NSError *_Nullable *error);
|
|
|
158 |
|
|
|
159 |
/** Writes the provided data to a file at the provided path. Intermediate directories will be
|
|
|
160 |
* created as needed.
|
|
|
161 |
* @param data The file content.
|
|
|
162 |
* @param filePath The path to the file to write the provided data.
|
|
|
163 |
* @param outError The error to populate if something goes wrong.
|
|
|
164 |
* @return `YES` in the case of success, `NO` otherwise.
|
|
|
165 |
*/
|
|
|
166 |
BOOL GDTCORWriteDataToFile(NSData *data, NSString *filePath, NSError *_Nullable *outError);
|
|
|
167 |
|
|
|
168 |
/** A typedef identify background identifiers. */
|
|
|
169 |
typedef volatile NSUInteger GDTCORBackgroundIdentifier;
|
|
|
170 |
|
|
|
171 |
/** A background task's invalid sentinel value. */
|
|
|
172 |
FOUNDATION_EXPORT const GDTCORBackgroundIdentifier GDTCORBackgroundIdentifierInvalid;
|
|
|
173 |
|
|
|
174 |
#if TARGET_OS_IOS || TARGET_OS_TV
|
|
|
175 |
/** A protocol that wraps UIApplicationDelegate, WKExtensionDelegate or NSObject protocol, depending
|
|
|
176 |
* on the platform.
|
|
|
177 |
*/
|
|
|
178 |
@protocol GDTCORApplicationDelegate <UIApplicationDelegate>
|
|
|
179 |
#elif TARGET_OS_OSX
|
|
|
180 |
@protocol GDTCORApplicationDelegate <NSApplicationDelegate>
|
|
|
181 |
#elif TARGET_OS_WATCH
|
|
|
182 |
@protocol GDTCORApplicationDelegate <WKExtensionDelegate>
|
|
|
183 |
#else
|
|
|
184 |
@protocol GDTCORApplicationDelegate <NSObject>
|
|
|
185 |
#endif // TARGET_OS_IOS || TARGET_OS_TV
|
|
|
186 |
|
|
|
187 |
@end
|
|
|
188 |
|
|
|
189 |
@protocol GDTCORApplicationProtocol <NSObject>
|
|
|
190 |
|
|
|
191 |
@required
|
|
|
192 |
|
|
|
193 |
/** Flag to determine if the application is running in the background. */
|
|
|
194 |
@property(atomic, readonly) BOOL isRunningInBackground;
|
|
|
195 |
|
|
|
196 |
/** Creates a background task with the returned identifier if on a suitable platform.
|
|
|
197 |
*
|
|
|
198 |
* @name name The name of the task, useful for debugging which background tasks are running.
|
|
|
199 |
* @param handler The handler block that is called if the background task expires.
|
|
|
200 |
* @return An identifier for the background task, or GDTCORBackgroundIdentifierInvalid if one
|
|
|
201 |
* couldn't be created.
|
|
|
202 |
*/
|
|
|
203 |
- (GDTCORBackgroundIdentifier)beginBackgroundTaskWithName:(NSString *)name
|
|
|
204 |
expirationHandler:(void (^__nullable)(void))handler;
|
|
|
205 |
|
|
|
206 |
/** Ends the background task if the identifier is valid.
|
|
|
207 |
*
|
|
|
208 |
* @param bgID The background task to end.
|
|
|
209 |
*/
|
|
|
210 |
- (void)endBackgroundTask:(GDTCORBackgroundIdentifier)bgID;
|
|
|
211 |
|
|
|
212 |
@end
|
|
|
213 |
|
|
|
214 |
/** A cross-platform application class. */
|
|
|
215 |
@interface GDTCORApplication : NSObject <GDTCORApplicationProtocol, GDTCORApplicationDelegate>
|
|
|
216 |
|
|
|
217 |
/** Creates and/or returns the shared application instance.
|
|
|
218 |
*
|
|
|
219 |
* @return The shared application instance.
|
|
|
220 |
*/
|
|
|
221 |
+ (nullable GDTCORApplication *)sharedApplication;
|
|
|
222 |
|
|
|
223 |
@end
|
|
|
224 |
|
|
|
225 |
NS_ASSUME_NONNULL_END
|