Determine which SIM is used to access the Internet

Initially, my task was to determine which type of connection is being used at the moment: 5G or 4G. And I found "CTTelephonyNetworkInfo().serviceCurrentRadioAccessTechnology" but there is a problem when the device has more than one sim. My iPhone has two sims, one physical and one electronic. I need to determine which one is used to access the network. I tried to use "CTTelephonyNetworkInfo().serviceCurrentRadioAccessTechnology" but it is a dictionary [String: String] that only indicates the connection of each of the cards, and it is not possible to find out which one is active from this dictionary. So how can I determine which of the two cards are currently being used to access the Internet?

Answered by Scott in 787596022

See this thread for an answer.

Having said that, also consider whether any network session APIs may meet your needs, such as allowsConstrainedNetworkAccess (link) and allowsExpensiveNetworkAccess (link).

Accepted Answer

See this thread for an answer.

Having said that, also consider whether any network session APIs may meet your needs, such as allowsConstrainedNetworkAccess (link) and allowsExpensiveNetworkAccess (link).

What Scott said plus…

You wrote:

which type of connection is being used at the moment: 5G or 4G.

Phrasing like this is a trap. In networking, you can only really talk about what was used, not what will be used. So if you have an open TCP connection you can reasonably ask what network interface and technology it’s currently using, but there’s no reliably way to predict the behaviour of a new connection.

Both Network framework and URLSession have APIs that reflect that reality:

  • In Network framework, you can request connection establishment and data transfer reports that include the radio technology. See Collecting Connection Metrics.

  • Likewise, for URLSession you have the URLSessionTaskMetrics class (that includes isCellular but no specific radio info).

Share and Enjoy

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

I will still know this and will be able to work with the new data, right?

Probably.

You’re assuming a bunch of things, but the big one is that things won’t change while a request is in flight. However, it may be hard to do better than this given that you’re working with URLSession.

Taking a step back, what are you using this info for? If you’re using it for telemetry then the above approach is probably fine; it’ll be right often enough that your metrics will be good enough. If you’re using it for something else, please explain what that is.

Share and Enjoy

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

Determine which SIM is used to access the Internet
 
 
Q