Skip to content

Commit 4149226

Browse files
authored
Wrap SCNetworkReachabilityFlags and fix Catalyst warning (#4965)
* wrap apis and fix catalyst warning * styled * add watchos * letters change
1 parent 595ee90 commit 4149226

File tree

5 files changed

+51
-38
lines changed

5 files changed

+51
-38
lines changed

.github/workflows/datatransport.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: macos-latest
1616
strategy:
1717
matrix:
18-
target: [ios, tvos, macos]
18+
target: [ios, tvos, macos, watchos]
1919
steps:
2020
- uses: actions/checkout@v2
2121
- name: Setup Bundler
@@ -32,7 +32,7 @@ jobs:
3232
if: github.event_name == 'schedule'
3333
strategy:
3434
matrix:
35-
target: [ios, tvos, macos]
35+
target: [ios, tvos, macos, watchos]
3636
flags: [
3737
'--use-modular-headers',
3838
'--use-libraries'

GoogleDataTransport/GDTCORLibrary/GDTCORPlatform.m

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@ BOOL GDTCORReachabilityFlagsContainWWAN(SCNetworkReachabilityFlags flags) {
5050
}
5151
#endif // !TARGET_OS_WATCH
5252

53+
GDTCORNetworkType GDTCORNetworkTypeMessage() {
54+
#if !TARGET_OS_WATCH
55+
SCNetworkReachabilityFlags reachabilityFlags = [GDTCORReachability currentFlags];
56+
if ((reachabilityFlags & kSCNetworkReachabilityFlagsReachable) ==
57+
kSCNetworkReachabilityFlagsReachable) {
58+
if (GDTCORReachabilityFlagsContainWWAN(reachabilityFlags)) {
59+
return GDTCORNetworkTypeMobile;
60+
} else {
61+
return GDTCORNetworkTypeWIFI;
62+
}
63+
}
64+
#endif
65+
return GDTCORNetworkTypeUNKNOWN;
66+
}
67+
5368
GDTCORNetworkMobileSubtype GDTCORNetworkMobileSubTypeMessage() {
5469
#if TARGET_OS_IOS
5570
static NSDictionary<NSString *, NSNumber *> *CTRadioAccessTechnologyToNetworkSubTypeMessage;
@@ -72,7 +87,14 @@ GDTCORNetworkMobileSubtype GDTCORNetworkMobileSubTypeMessage() {
7287
networkInfo = [[CTTelephonyNetworkInfo alloc] init];
7388
});
7489
NSString *networkCurrentRadioAccessTechnology;
75-
if (@available(iOS 12, *)) {
90+
#if TARGET_OS_MACCATALYST
91+
NSDictionary<NSString *, NSString *> *networkCurrentRadioAccessTechnologyDict =
92+
networkInfo.serviceCurrentRadioAccessTechnology;
93+
if (networkCurrentRadioAccessTechnologyDict.count) {
94+
networkCurrentRadioAccessTechnology = networkCurrentRadioAccessTechnologyDict.allValues[0];
95+
}
96+
#else
97+
if (@available(iOS 12.0, *)) {
7698
NSDictionary<NSString *, NSString *> *networkCurrentRadioAccessTechnologyDict =
7799
networkInfo.serviceCurrentRadioAccessTechnology;
78100
if (networkCurrentRadioAccessTechnologyDict.count) {
@@ -83,6 +105,7 @@ GDTCORNetworkMobileSubtype GDTCORNetworkMobileSubTypeMessage() {
83105
} else {
84106
networkCurrentRadioAccessTechnology = networkInfo.currentRadioAccessTechnology;
85107
}
108+
#endif
86109
if (networkCurrentRadioAccessTechnology) {
87110
NSNumber *networkMobileSubtype =
88111
CTRadioAccessTechnologyToNetworkSubTypeMessage[networkCurrentRadioAccessTechnology];

GoogleDataTransport/GDTCORLibrary/Public/GDTCORPlatform.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ FOUNDATION_EXPORT NSString *const kGDTCORApplicationWillEnterForegroundNotificat
4343
/** A notification sent out if the app is terminating. */
4444
FOUNDATION_EXPORT NSString *const kGDTCORApplicationWillTerminateNotification;
4545

46+
/** The different possible network connection type. */
47+
typedef NS_ENUM(NSInteger, GDTCORNetworkType) {
48+
GDTCORNetworkTypeUNKNOWN = 0,
49+
GDTCORNetworkTypeWIFI = 1,
50+
GDTCORNetworkTypeMobile = 2,
51+
};
52+
4653
/** The different possible network connection mobile subtype. */
4754
typedef NS_ENUM(NSInteger, GDTCORNetworkMobileSubtype) {
4855
GDTCORNetworkMobileSubtypeUNKNOWN = 0,
@@ -68,7 +75,13 @@ typedef NS_ENUM(NSInteger, GDTCORNetworkMobileSubtype) {
6875
BOOL GDTCORReachabilityFlagsContainWWAN(SCNetworkReachabilityFlags flags);
6976
#endif
7077

71-
/** Generates an enum message GDTCORNetworkMobileSubtype representing Network connection mobile
78+
/** Generates an enum message GDTCORNetworkType representing network connection type.
79+
*
80+
* @return A GDTCORNetworkType representing network connection type.
81+
*/
82+
GDTCORNetworkType GDTCORNetworkTypeMessage(void);
83+
84+
/** Generates an enum message GDTCORNetworkMobileSubtype representing network connection mobile
7285
* subtype.
7386
*
7487
* @return A GDTCORNetworkMobileSubtype representing network connection mobile subtype.

GoogleDataTransportCCTSupport/GDTCCTLibrary/GDTCCTNanopbHelpers.m

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -199,40 +199,25 @@ gdt_cct_IosClientInfo GDTCCTConstructiOSClientInfo() {
199199

200200
NSData *GDTCCTConstructNetworkConnectionInfoData() {
201201
gdt_cct_NetworkConnectionInfo networkConnectionInfo = gdt_cct_NetworkConnectionInfo_init_default;
202-
SCNetworkReachabilityFlags reachabilityFlags = [GDTCORReachability currentFlags];
203-
if ((reachabilityFlags & kSCNetworkReachabilityFlagsReachable) ==
204-
kSCNetworkReachabilityFlagsReachable) {
205-
networkConnectionInfo.network_type = GDTCCTNetworkConnectonInfoNetworkType(reachabilityFlags);
206-
if (networkConnectionInfo.network_type != gdt_cct_NetworkConnectionInfo_NetworkType_NONE) {
207-
networkConnectionInfo.has_network_type = 1;
208-
if (networkConnectionInfo.network_type == gdt_cct_NetworkConnectionInfo_NetworkType_MOBILE) {
209-
networkConnectionInfo.mobile_subtype = GDTCCTNetworkConnectionInfoNetworkMobileSubtype();
210-
if (networkConnectionInfo.mobile_subtype !=
211-
gdt_cct_NetworkConnectionInfo_MobileSubtype_UNKNOWN_MOBILE_SUBTYPE) {
212-
networkConnectionInfo.has_mobile_subtype = 1;
213-
}
202+
NSInteger currentNetworkType = GDTCORNetworkTypeMessage();
203+
if (currentNetworkType) {
204+
networkConnectionInfo.has_network_type = 1;
205+
if (currentNetworkType == GDTCORNetworkTypeMobile) {
206+
networkConnectionInfo.network_type = gdt_cct_NetworkConnectionInfo_NetworkType_MOBILE;
207+
networkConnectionInfo.mobile_subtype = GDTCCTNetworkConnectionInfoNetworkMobileSubtype();
208+
if (networkConnectionInfo.mobile_subtype !=
209+
gdt_cct_NetworkConnectionInfo_MobileSubtype_UNKNOWN_MOBILE_SUBTYPE) {
210+
networkConnectionInfo.has_mobile_subtype = 1;
214211
}
212+
} else {
213+
networkConnectionInfo.network_type = gdt_cct_NetworkConnectionInfo_NetworkType_WIFI;
215214
}
216215
}
217216
NSData *networkConnectionInfoData = [NSData dataWithBytes:&networkConnectionInfo
218217
length:sizeof(networkConnectionInfo)];
219218
return networkConnectionInfoData;
220219
}
221220

222-
gdt_cct_NetworkConnectionInfo_NetworkType GDTCCTNetworkConnectonInfoNetworkType(
223-
SCNetworkReachabilityFlags flags) {
224-
gdt_cct_NetworkConnectionInfo_NetworkType networkType =
225-
gdt_cct_NetworkConnectionInfo_NetworkType_NONE;
226-
if (GDTCORReachabilityFlagsContainWWAN(flags)) {
227-
networkType = gdt_cct_NetworkConnectionInfo_NetworkType_MOBILE;
228-
GDTCORLogDebug(@"%@", @"Event captured that it occurred whilst using mobile data.");
229-
} else {
230-
networkType = gdt_cct_NetworkConnectionInfo_NetworkType_WIFI;
231-
GDTCORLogDebug(@"%@", @"Event captured that it occurred whilst using wifi data.");
232-
}
233-
return networkType;
234-
}
235-
236221
gdt_cct_NetworkConnectionInfo_MobileSubtype GDTCCTNetworkConnectionInfoNetworkMobileSubtype() {
237222
NSNumber *networkMobileSubtypeMessage = @(GDTCORNetworkMobileSubTypeMessage());
238223
if (!networkMobileSubtypeMessage.intValue) {

GoogleDataTransportCCTSupport/GDTCCTLibrary/Private/GDTCCTNanopbHelpers.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,6 @@ gdt_cct_IosClientInfo GDTCCTConstructiOSClientInfo(void);
115115
FOUNDATION_EXPORT
116116
NSData *GDTCCTConstructNetworkConnectionInfoData(void);
117117

118-
/** Return a gdt_cct_NetworkConnectionInfo_NetworkType representing the cilent network type.
119-
*
120-
* @return The gdt_cct_NetworkConnectionInfo_NetworkType.
121-
*/
122-
FOUNDATION_EXPORT
123-
gdt_cct_NetworkConnectionInfo_NetworkType GDTCCTNetworkConnectonInfoNetworkType(
124-
SCNetworkReachabilityFlags flags);
125-
126118
/** Return a gdt_cct_NetworkConnectionInfo_MobileSubtype representing the client
127119
*
128120
* @return The gdt_cct_NetworkConnectionInfo_MobileSubtype.

0 commit comments

Comments
 (0)