PlugN
PlugN

Reputation: 49

How to handle serviceSubscriberCellularProviders to get only data from physical SIM card instead of the eSIM?

All right, so I have an app that requires reading the data from the SIM card. More precisely I need the Carrier name, MCC, MNC, ISO Country code and current Radio Access Technology (Okay this does not directly come from the SIM card but it is linked). It works perfectly on every phone, but I realized (after testing) that I'm in trouble with the newest iPhones that have an eSIM set up. I have no idea how to tell my app to read the data of the physical SIM card instead of the eSIM.

I tried to search a bit on the Web about that but I found absolutely nothing...

let telephonyInfo: CTTelephonyNetworkInfo = CTTelephonyNetworkInfo()

carrierNetwork = telephonyInfo.serviceCurrentRadioAccessTechnology?.first?.value ?? "null"
carrierNetwork = carrierNetwork.replacingOccurrences(of: "CTRadioAccessTechnology", with: "", options: NSString.CompareOptions.literal, range: nil)

let carrier = telephonyInfo.serviceSubscriberCellularProviders?.first?.value // actually here originally I tried to use ?.values.first, but the result is the same

let countryCode = carrier?.mobileCountryCode ?? "null"
let mobileNetworkName = carrier?.mobileNetworkCode ?? "null"
let carrierName = carrier?.carrierName ?? "null"
let isoCountrycode = carrier?.isoCountryCode?.uppercased() ?? "null"

/* so the problem is that the values I get are the ones from the eSIM when it is set up. If it is not, then I get the values I want. Apparently, when the physical SIM card line is set as primary, it works. But I need that code to systematically use the physical SIM data. */

Example :

I expect [physical SIM card]: Carrier name: Free, MCC: 208, MNC: 15, ISO Country Code: fr, CTRadioAccessTechnology: WCDMA.

But instead, I get [eSIM]: Carrier name: Swisscom, MCC: 228, MNC: 01, ISO Country Code: ch, CTRadioAccessTechnology: LTE.

EDIT: If you know how I can read both, that's also fine to me, my goal is to detect if the user uses a Free Mobile [208 15] SIM card.

Upvotes: 3

Views: 2087

Answers (1)

Anton Makeev
Anton Makeev

Reputation: 21

let carriers = telephonyInfo.serviceSubscriberCellularProviders?.values

will result in optinal array. Go through and check if it is "Free"

Still no idea how to detect eSim or physical

Upvotes: 0

Related Questions