Copilot commented on code in PR #169:
URL:
https://github.com/apache/cordova-plugin-network-information/pull/169#discussion_r2996417882
##########
src/ios/CDVConnection.m:
##########
@@ -101,6 +101,20 @@ -
(NSString*)w3cConnectionTypeFor:(CDVReachability*)reachability
}
}
+- (NSString*)currentRadioAccessTechnology
+{
+ CTTelephonyNetworkInfo *telephonyInfo = [CTTelephonyNetworkInfo new];
Review Comment:
New private method `-currentRadioAccessTechnology` isn’t declared in the
existing `CDVConnection (PrivateMethods)` category at the top of the file.
Declaring it there keeps private API consistent with the file’s pattern and
avoids potential missing-prototype / signature checking issues.
##########
src/ios/CDVConnection.m:
##########
@@ -101,6 +101,20 @@ -
(NSString*)w3cConnectionTypeFor:(CDVReachability*)reachability
}
}
+- (NSString*)currentRadioAccessTechnology
+{
+ CTTelephonyNetworkInfo *telephonyInfo = [CTTelephonyNetworkInfo new];
+
+ if (@available(iOS 12.0, *)) {
+ return
telephonyInfo.serviceCurrentRadioAccessTechnology.allValues.firstObject;
Review Comment:
`serviceCurrentRadioAccessTechnology` is a dictionary (multi‑SIM). Using
`allValues.firstObject` is non-deterministic and can report the wrong RAT when
multiple services exist. Prefer selecting the RAT for the active data service
(e.g., via `dataServiceIdentifier` when available) and fall back
deterministically when it’s not.
```suggestion
NSDictionary<NSString*, NSString*> *ratByService =
telephonyInfo.serviceCurrentRadioAccessTechnology;
if (ratByService.count == 0) {
return nil;
}
NSString *currentRAT = nil;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
if (@available(iOS 13.0, *)) {
NSString *dataServiceIdentifier =
telephonyInfo.dataServiceIdentifier;
if (dataServiceIdentifier.length > 0) {
currentRAT = ratByService[dataServiceIdentifier];
}
}
#endif
if (!currentRAT) {
NSArray<NSString*> *sortedKeys = [[ratByService allKeys]
sortedArrayUsingSelector:@selector(compare:)];
NSString *firstKey = sortedKeys.firstObject;
currentRAT = firstKey != nil ? ratByService[firstKey] : nil;
}
return currentRAT;
```
##########
src/ios/CDVConnection.m:
##########
@@ -151,8 +165,16 @@ - (void)pluginInitialize
[self.internetReach startNotifier];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateConnectionType:)
name:kReachabilityChangedNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateConnectionType:)
-
name:CTRadioAccessTechnologyDidChangeNotification object:nil];
+ if (@available(iOS 12.0, *)) {
+ [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateConnectionType:)
+
name:CTServiceRadioAccessTechnologyDidChangeNotification object:nil];
+ } else {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateConnectionType:)
+
name:CTRadioAccessTechnologyDidChangeNotification object:nil];
+#pragma clang diagnostic pop
Review Comment:
The telephony notification observers call `updateConnectionType:`, but that
handler only updates when `note.object` is a `CDVReachability` instance.
CoreTelephony change notifications don’t provide a `CDVReachability` object, so
these observers won’t refresh `connectionType`. Consider adding a dedicated
handler for radio tech changes (or make `updateConnectionType:` fall back to
updating using `self.internetReach`).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]