commit | author | age
|
a6c014
|
1 |
/* |
L |
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 |
/** A typedef identify background identifiers. */ |
|
160 |
typedef volatile NSUInteger GDTCORBackgroundIdentifier; |
|
161 |
|
|
162 |
/** A background task's invalid sentinel value. */ |
|
163 |
FOUNDATION_EXPORT const GDTCORBackgroundIdentifier GDTCORBackgroundIdentifierInvalid; |
|
164 |
|
|
165 |
#if TARGET_OS_IOS || TARGET_OS_TV |
|
166 |
/** A protocol that wraps UIApplicationDelegate, WKExtensionDelegate or NSObject protocol, depending |
|
167 |
* on the platform. |
|
168 |
*/ |
|
169 |
@protocol GDTCORApplicationDelegate <UIApplicationDelegate> |
|
170 |
#elif TARGET_OS_OSX |
|
171 |
@protocol GDTCORApplicationDelegate <NSApplicationDelegate> |
|
172 |
#elif TARGET_OS_WATCH |
|
173 |
@protocol GDTCORApplicationDelegate <WKExtensionDelegate> |
|
174 |
#else |
|
175 |
@protocol GDTCORApplicationDelegate <NSObject> |
|
176 |
#endif // TARGET_OS_IOS || TARGET_OS_TV |
|
177 |
|
|
178 |
@end |
|
179 |
|
|
180 |
/** A cross-platform application class. */ |
|
181 |
@interface GDTCORApplication : NSObject <GDTCORApplicationDelegate> |
|
182 |
|
|
183 |
/** Flag to determine if the application is running in the background. */ |
|
184 |
@property(atomic, readonly) BOOL isRunningInBackground; |
|
185 |
|
|
186 |
/** Creates and/or returns the shared application instance. |
|
187 |
* |
|
188 |
* @return The shared application instance. |
|
189 |
*/ |
|
190 |
+ (nullable GDTCORApplication *)sharedApplication; |
|
191 |
|
|
192 |
/** Creates a background task with the returned identifier if on a suitable platform. |
|
193 |
* |
|
194 |
* @name name The name of the task, useful for debugging which background tasks are running. |
|
195 |
* @param handler The handler block that is called if the background task expires. |
|
196 |
* @return An identifier for the background task, or GDTCORBackgroundIdentifierInvalid if one |
|
197 |
* couldn't be created. |
|
198 |
*/ |
|
199 |
- (GDTCORBackgroundIdentifier)beginBackgroundTaskWithName:(NSString *)name |
|
200 |
expirationHandler:(void (^__nullable)(void))handler; |
|
201 |
|
|
202 |
/** Ends the background task if the identifier is valid. |
|
203 |
* |
|
204 |
* @param bgID The background task to end. |
|
205 |
*/ |
|
206 |
- (void)endBackgroundTask:(GDTCORBackgroundIdentifier)bgID; |
|
207 |
|
|
208 |
@end |
|
209 |
|
|
210 |
NS_ASSUME_NONNULL_END |