Skip to content

Commit

Permalink
Adds 5g to network reachability checks
Browse files Browse the repository at this point in the history
  • Loading branch information
rcrahul43 committed Apr 22, 2024
1 parent b696976 commit 74e5bea
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ enum NetworkType: Equatable {
case wwan2g
case wwan3g
case wwan4g
case wwan5g
case unknownTechnology(name: String)

var trackingId: String {
Expand All @@ -27,6 +28,7 @@ enum NetworkType: Equatable {
case .wwan2g: return "2G"
case .wwan3g: return "3G"
case .wwan4g: return "4G"
case .wwan5g: return "5G"
case .unknownTechnology(let name): return "Unknown Technology: \"\(name)\""
}
}
Expand All @@ -51,7 +53,18 @@ extension Reachability {
}

internal static func getWWANNetworkType() -> NetworkType {
guard let currentRadioAccessTechnology = CTTelephonyNetworkInfo().currentRadioAccessTechnology else { return .unknown }
var _currentRadioAccessTechnology: String? = nil
if let accessTechnology = CTTelephonyNetworkInfo().serviceCurrentRadioAccessTechnology?.values.first{
_currentRadioAccessTechnology = accessTechnology
}

guard let currentRadioAccessTechnology = _currentRadioAccessTechnology else { return .unknown }

if #available(iOS 14.1, *) {
if currentRadioAccessTechnology == CTRadioAccessTechnologyNRNSA || currentRadioAccessTechnology == CTRadioAccessTechnologyNR{
return .wwan5g
}
}
switch currentRadioAccessTechnology {
case CTRadioAccessTechnologyGPRS,
CTRadioAccessTechnologyEdge,
Expand All @@ -70,5 +83,5 @@ extension Reachability {
default:
return .unknownTechnology(name: currentRadioAccessTechnology)
}
}
}
}

0 comments on commit 74e5bea

Please sign in to comment.