I would like to get user's current country without asking for location. So I thought using CTCarrier
class property isoCountryCode
. To get access to CTCarrier
I'm using serviceSubscriberCellularProviders
, which returns "A dictionary that contains carrier information about each service".
https://developer.apple.com/documentation/coretelephony/cttelephonynetworkinfo/3024511-servicesubscribercellularprovide.
Now when I query serviceSubscriberCellularProviders
it returns 2 objects - nil
and presumably my home cellular service provider.
let networkInfo = CTTelephonyNetworkInfo()
let dictionary = networkInfo.serviceSubscriberCellularProviders;
for (type, value) in dictionary ?? [:] {
let country:String? = value.isoCountryCode == nil ? "nil" : value.isoCountryCode;
print("serviceSubscriberCellularProviders: " country!)
}
If I was abroad and connected to roaming service provider would I still get two objects - home and now instead of nil
- roaming service provider? And inside roaming service provider property isoCountryCode
would return the actual country of the roaming service provider?
The documentation is confusing for me... What exactly is isoCountryCode
for home cellular service provider? Let's say I live in France and my service provider is of course from France - isoCountryCode
would return "FR". Now if I go on a vacation to Germany - what isoCountryCode
would return now? Still the same "FR" or "DE"?
CodePudding user response:
As the documentation explains:
Note
In this context, the “home” provider is the one with which the user has a cellular plan, as opposed to a roaming provider.
So, you will always get FR, even when roaming, if your home provider is in France.
The reason there are two possible values is that iPhones now support up to two sims; One physical and one e-SIM, so there may be two different cellular providers on a phone.