How to get country code by using CoreTelephony in iOS?

329 views Asked by At

I am using CoreTelephony for get country code from the sim in the iOS device.

I have seen the discussion here. But isoCountryCode is deprecated from ios 16 onwards. I got key(0000000100000001) from serviceCurrentRadioAccessTechnology, and pass the key through serviceSubscriberCellularProviders.

This is the code:

if #available(iOS 12.0, *){
    if let providers = CTTelephonyNetworkInfo().serviceCurrentRadioAccessTechnology {    
        providers.forEach { (key, value) in
            if let temp:[String:CTCarrier] = CTTelephonyNetworkInfo().serviceSubscriberCellularProviders{
                if let simData:CTCarrier = temp[key]{
                    let code:String = simData.isoCountryCode ?? "no data"
                    print(code)
                }
            }
        }
    }
}

and got an output like this because the testing device is in ios 16.

--

Is there any way to get country code from the SIM.

0

There are 0 answers