Skip to content

Commit d88517d

Browse files
ios: add 5G check (#159)
Co-authored-by: Manuel Beck <manuelbeck87@outlook.de>
1 parent 952bd51 commit d88517d

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ wifi connection, and whether the device has an internet connection.
6262
- Connection.CELL_2G
6363
- Connection.CELL_3G
6464
- Connection.CELL_4G
65+
- Connection.CELL_5G
6566
- Connection.CELL
6667
- Connection.NONE
6768

@@ -83,6 +84,7 @@ function checkConnection() {
8384
states[Connection.CELL_2G] = 'Cell 2G connection';
8485
states[Connection.CELL_3G] = 'Cell 3G connection';
8586
states[Connection.CELL_4G] = 'Cell 4G connection';
87+
states[Connection.CELL_5G] = 'Cell 5G connection';
8688
states[Connection.CELL] = 'Cell generic connection';
8789
states[Connection.NONE] = 'No network connection';
8890

src/ios/CDVConnection.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ - (NSString*)w3cConnectionTypeFor:(CDVReachability*)reachability
8383
return @"3g";
8484
} else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyLTE]) {
8585
return @"4g";
86+
// 5G available since iOS 14.1
87+
} else if (@available(iOS 14.1, *)) {
88+
if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyNRNSA]) {
89+
return @"5g";
90+
} else if ([telephonyInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyNR]) {
91+
return @"5g";
92+
}
8693
}
8794
}
8895
return @"cellular";
@@ -107,6 +114,7 @@ - (BOOL)isCellularConnection:(NSString*)theConnectionType
107114
return [theConnectionType isEqualToString:@"2g"] ||
108115
[theConnectionType isEqualToString:@"3g"] ||
109116
[theConnectionType isEqualToString:@"4g"] ||
117+
[theConnectionType isEqualToString:@"5g"] ||
110118
[theConnectionType isEqualToString:@"cellular"];
111119
}
112120

types/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ interface Connection {
4242
* Connection.CELL_2G
4343
* Connection.CELL_3G
4444
* Connection.CELL_4G
45+
* Connection.CELL_5G
4546
* Connection.CELL
4647
* Connection.NONE
4748
*/
@@ -57,6 +58,7 @@ declare var Connection: {
5758
CELL_2G: string;
5859
CELL_3G: string;
5960
CELL_4G: string;
61+
CELL_5G: string;
6062
CELL: string;
6163
NONE: string;
6264
}

www/Connection.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module.exports = {
2727
CELL_2G: '2g',
2828
CELL_3G: '3g',
2929
CELL_4G: '4g',
30+
CELL_5G: '5g',
3031
CELL: 'cellular',
3132
NONE: 'none'
3233
};

0 commit comments

Comments
 (0)