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 ?? ""))
}