Reputation: 55
iPhoneXr/iPhone11 have two sim cards, so the variable serviceSubscriberCellularProviders
will have two values. Is there a way to get the one that is currently in use?
=================
Update:modified answer from Mathias
written below:
import CoreTelephony
if #available(iOS 13.0, *) {
let networkInfo = CTTelephonyNetworkInfo()
if let dataServiceIdentifier = networkInfo.dataServiceIdentifier,
let allProviders = networkInfo.serviceSubscriberCellularProviders,
let currentProvider = allProviders[dataServiceIdentifier]
{
print("\(currentProvider)")
}
}
Upvotes: 1
Views: 1104
Reputation: 566
Apple did not document well this area since iOS 13 but this would work if you consider that the current data provider should be the serviceProvider currently in use :
import CoreTelephony
let networkInfo = CTTelephonyNetworkInfo()
let dataServiceIdentifier = networkInfo.dataServiceIdentifier
let currentProvider = networkInfo.serviceSubscriberCellularProviders![dataServiceIdentifier!]
Upvotes: 2