I have a singleton observing CTServiceRadioAccessTechnologyDidChange notification from there we unwrap telephonyInfo.serviceCurrentRadioAccessTechnology
dictionary with notification.object
and then compare to Radio Access Tech friendly names.
We do the above to detect when device changes from 3G to 4G (that is the end goal) but the notification does not consistent update.
When testing on device we switch in Settings -> Cellular -> Cellular Data Options -> Voice & Data
between LTE and 3G and at times the notification does not accurate reflect when device switches to 3G or back to LTE, it gets stuck in 3G or LTE.
Below is the code implementation:
func initializeRadioAccessMonitor() {
let carrierType = telephonyInfo.serviceCurrentRadioAccessTechnology
if let radioTech = carrierType?.first?.value {
self.classifyRadioAccessTech(identifier: radioTech)
}
NotificationCenter.default.addObserver(self, selector: #selector(radioAccessChanged), name: .CTServiceRadioAccessTechnologyDidChange, object: nil)
}
@objc func radioAccessChanged(_ notification: Notification) {
let identifier = notification.object as! String
if let radioAccess = telephonyInfo.serviceCurrentRadioAccessTechnology?[identifier] {
self.classifyRadioAccessTech(identifier: radioAccess)
} else {
print("[DEBUG] Error unable to unwrap radio access")
}
}
func classifyRadioAccessTech(identifier: String) {
print("[DEBUG] Radio Access technology: \(identifier)")
if #available(iOS 14.1, *) {
switch identifier {
case CTRadioAccessTechnologyGPRS, CTRadioAccessTechnologyEdge:
radioAccessSpeed = .lowSpeed
case CTRadioAccessTechnologyLTE:
radioAccessSpeed = .highSpeed
case CTRadioAccessTechnologyNRNSA, CTRadioAccessTechnologyNR:
radioAccessSpeed = .superSpeed
default:
radioAccessSpeed = .mediumSpeed
}
} else {
switch identifier {
case CTRadioAccessTechnologyGPRS, CTRadioAccessTechnologyEdge:
radioAccessSpeed = .lowSpeed
case CTRadioAccessTechnologyLTE:
radioAccessSpeed = .highSpeed
default:
radioAccessSpeed = .mediumSpeed
}
}
}
Am I observing the wrong notification or is there a better way to detect changes between 3G and 4G.
System details: Xcode 13.0
Device details: iPad 6th Gen LTE - PadOS 15 iPad 8th Gen LTE - PadOS 14.7.1