The public API CTTelephonyNetworkInfo of Apple is returning wrong MNC in romaing

When user moves from area serving 'X' network operator ex:(MCC : 123 and MNC:10)  to an area serving 'X' Roaming operator (MCC:123 and MNC:20), the public API of Apple is returning MNC as 10 in 'X' Roaming operator which is affecting our application usage, whereas the private API using hashcode is returning MNC as 20.
Answered by Netvelocity in 677672022

Below function we are using

static func getMccMnc() -> (mcc: String, mnc: String) {
    let bgTask = UIApplication.shared.beginBackgroundTask {
      print("BackgroundTask Expired")
    }
     
    let networkInfo = CTTelephonyNetworkInfo()
    var carrier: [String:CTCarrier]? = nil
     
    if #available(iOS 13.0, *) {
      guard let str = networkInfo.dataServiceIdentifier else {
        UIApplication.shared.endBackgroundTask(bgTask)
        return ("","") }
      carrier = networkInfo.serviceSubscriberCellularProviders
      let ctCarrier = carrier?[str]
      guard let _ = ctCarrier?.mobileCountryCode, let _ = ctCarrier?.mobileNetworkCode else {
        UIApplication.shared.endBackgroundTask(bgTask)
        return ("","")}
      UIApplication.shared.endBackgroundTask(bgTask)
      return ((ctCarrier?.mobileCountryCode ?? ""), (ctCarrier?.mobileNetworkCode ?? ""))
       
    }

the public API of Apple is returning MNC

Which public API specifically?

the private API

DevForums is focused on public APIs, as published in Apple’s various platform SDKs. If you’re working on behalf of a carrier and have a question about carrier-specific facilities, you should escalate that with your carrier contact at Apple.

Share and Enjoy

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

Please reply using the Your Answer field. The Comment field is not suitable for large, formatted responses.

Share and Enjoy

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

We are using this to get the MCC & MNC let networkInfo = CTTelephonyNetworkInfo()    var carrier: [String:CTCarrier]? = nil         if #available(iOS 13.0, *) {      guard let str = networkInfo.dataServiceIdentifier else {        UIApplication.shared.endBackgroundTask(bgTask)        return ("","") }      carrier = networkInfo.serviceSubscriberCellularProviders      let ctCarrier = carrier?[str]      guard let _ = ctCarrier?.mobileCountryCode, let _ = ctCarrier?.mobileNetworkCode else {        UIApplication.shared.endBackgroundTask(bgTask)        return ("","")}      UIApplication.shared.endBackgroundTask(bgTask)      //NewChanges      return ((ctCarrier?.mobileCountryCode ?? ""), (ctCarrier?.mobileNetworkCode ?? ""))}

This code give wrong MNC in Roaming

That’s not an improvement )-:

The DevForums text editor supports a variety of Markdown-like formatting options, including triple backticks to denote a code block (or just click the Code Block button). If you repost you code so that I can read it, I’ll see if I can work out what’s going on.

Share and Enjoy

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

Accepted Answer

Below function we are using

static func getMccMnc() -> (mcc: String, mnc: String) {
    let bgTask = UIApplication.shared.beginBackgroundTask {
      print("BackgroundTask Expired")
    }
     
    let networkInfo = CTTelephonyNetworkInfo()
    var carrier: [String:CTCarrier]? = nil
     
    if #available(iOS 13.0, *) {
      guard let str = networkInfo.dataServiceIdentifier else {
        UIApplication.shared.endBackgroundTask(bgTask)
        return ("","") }
      carrier = networkInfo.serviceSubscriberCellularProviders
      let ctCarrier = carrier?[str]
      guard let _ = ctCarrier?.mobileCountryCode, let _ = ctCarrier?.mobileNetworkCode else {
        UIApplication.shared.endBackgroundTask(bgTask)
        return ("","")}
      UIApplication.shared.endBackgroundTask(bgTask)
      return ((ctCarrier?.mobileCountryCode ?? ""), (ctCarrier?.mobileNetworkCode ?? ""))
       
    }

OK, looking at this code it seems that you care about the mobileCountryCode and mobileNetworkCode properties of the CTCarrier object. And going back to your original post it sounds like you want these to reflect the device’s roaming status. That is, if the user roams from their ‘home’ network you want these values to return the value of the foreign network. Is that right?

If so, this won’t work, and to understand this you just need to look at the name of the property where you’re getting your CTCarrier value, namely serviceSubscriberCellularProviders. This is returns subscriber information, that is, it always returns information about their home network. The docs make this very clear:

In this context, the “home” provider is the one with which the user has a cellular plan, as opposed to a roaming provider.

There are no APIs in the iOS SDK that return information about the device’s current network.

Share and Enjoy

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

The public API CTTelephonyNetworkInfo of Apple is returning wrong MNC in romaing
 
 
Q