Failed to monitor cellular network changes from 4G to 5G or 5G to 4G

I want to observe network changes from 4G to 5G use the following code:

   if (@available(iOS 12.0, *)) {
    [[NSNotificationCenter defaultCenter] addObserverForName:CTServiceRadioAccessTechnologyDidChangeNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
    }];
  }

When I switch my phone's network from 4G to 5G, it do not work。but when I switch my network between 3G and 4G, it did work.

when I switch network to 5G, I run CTTelephonyNetworkInfo.new.serviceCurrentRadioAccessTechnology ,it did return CTRadioAccessTechnologyNR which is 5G。

Question

  1. is there a bug on CTServiceRadioAccessTechnologyDidChangeNotification when net changes between 4G and 5G?
  2. is there a way to know network changes between 4G and 5G? Exclude polling。

The code you posted doesn’t look right. When you use -addObserverForName:object:queue:usingBlock: you are expected to retain the returned token; releasing it remove the observer.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Not work for me to ,

   [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(__onRadioAccessTechonologyDidChanged) name:CTServiceRadioAccessTechnologyDidChangeNotification object:nil];

__onRadioAccessTechonologyDidChanged not called, when i switch 5G to 4G in IOS Setting

when i switch 5G to 4G in iOS [Settings]

To change this in Settings you have to move your app to the background. I haven’t tested this recently but, at least in the past, CT did not do a good job of handling this. My general advice is that you tear down your CT stack when your app becomes eligible for suspension and then rebuild it when your app is running again.

If you do that, do you see the change? Your observer won’t be called, because your CT stack is torn down at the time that you make the change, but you should see the new value when you bring it back up.

ps Why do you care about the current radio technology?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Failed to monitor cellular network changes from 4G to 5G or 5G to 4G
 
 
Q