You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ma...@apache.org on 2026/03/26 17:00:10 UTC
(cordova-plugin-network-information) 01/01: fix(ios): fix deprecation warnings for iOS 12+
This is an automated email from the ASF dual-hosted git repository.
manuelbeck pushed a commit to branch pr-ios-fix-deprecation-warnings
in repository https://gitbox.apache.org/repos/asf/cordova-plugin-network-information.git
commit 1e316f353779a12e7c57bfbc15b8f0704a62dd76
Author: Manuel Beck <ma...@outlook.de>
AuthorDate: Thu Mar 26 17:59:58 2026 +0100
fix(ios): fix deprecation warnings for iOS 12+
- `currentRadioAccessTechnology` is deprecated since iOS 12: https://developer.apple.com/documentation/coretelephony/cttelephonynetworkinfo/currentradioaccesstechnology?language=objc.`serviceCurrentRadioAccessTechnology` should be used.
- Add method `currentRadioAccessTechnology` which uses `serviceCurrentRadioAccessTechnology` on iOS 12 and newer and `currentRadioAccessTechnology` on iOS 11 and older
- `CTRadioAccessTechnologyDidChangeNotification` is deprecated since iOS 12: https://developer.apple.com/documentation/coretelephony/ctradioaccesstechnologydidchangenotification?language=objc. Instead `CTServiceRadioAccessTechnologyDidChangeNotification` should be used.
---
src/ios/CDVConnection.m | 50 +++++++++++++++++++++++++++++++++++--------------
1 file changed, 36 insertions(+), 14 deletions(-)
diff --git a/src/ios/CDVConnection.m b/src/ios/CDVConnection.m
index 40b2e42..06273a0 100644
--- a/src/ios/CDVConnection.m
+++ b/src/ios/CDVConnection.m
@@ -59,28 +59,28 @@
return @"none";
} else {
if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending) {
- CTTelephonyNetworkInfo *telephonyInfo = [CTTelephonyNetworkInfo new];
- if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyGPRS]) {
+ NSString* radioAccessTechnology = [self currentRadioAccessTechnology];
+ if ([radioAccessTechnology isEqualToString:CTRadioAccessTechnologyGPRS]) {
return @"2g";
- } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyEdge]) {
+ } else if ([radioAccessTechnology isEqualToString:CTRadioAccessTechnologyEdge]) {
return @"2g";
- } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyWCDMA]) {
+ } else if ([radioAccessTechnology isEqualToString:CTRadioAccessTechnologyWCDMA]) {
return @"3g";
- } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyHSDPA]) {
+ } else if ([radioAccessTechnology isEqualToString:CTRadioAccessTechnologyHSDPA]) {
return @"3g";
- } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyHSUPA]) {
+ } else if ([radioAccessTechnology isEqualToString:CTRadioAccessTechnologyHSUPA]) {
return @"3g";
- } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMA1x]) {
+ } else if ([radioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMA1x]) {
return @"3g";
- } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORev0]) {
+ } else if ([radioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORev0]) {
return @"3g";
- } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORevA]) {
+ } else if ([radioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORevA]) {
return @"3g";
- } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORevB]) {
+ } else if ([radioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORevB]) {
return @"3g";
- } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyeHRPD]) {
+ } else if ([radioAccessTechnology isEqualToString:CTRadioAccessTechnologyeHRPD]) {
return @"3g";
- } else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyLTE]) {
+ } else if ([radioAccessTechnology isEqualToString:CTRadioAccessTechnologyLTE]) {
return @"4g";
}
}
@@ -101,6 +101,20 @@
}
}
+- (NSString*)currentRadioAccessTechnology
+{
+ CTTelephonyNetworkInfo *telephonyInfo = [CTTelephonyNetworkInfo new];
+
+ if (@available(iOS 12.0, *)) {
+ return telephonyInfo.serviceCurrentRadioAccessTechnology.allValues.firstObject;
+ }
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ return telephonyInfo.currentRadioAccessTechnology;
+#pragma clang diagnostic pop
+}
+
- (BOOL)isCellularConnection:(NSString*)theConnectionType
{
return [theConnectionType isEqualToString:@"2g"] ||
@@ -151,8 +165,16 @@
[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
+ }
if (UIApplicationDidEnterBackgroundNotification && UIApplicationWillEnterForegroundNotification) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onPause) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onResume) name:UIApplicationWillEnterForegroundNotification object:nil];
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org