当iPhone Xs,12.1只有eSIM时,我如何获得mobileCountryCode



我没有从iPhone中找到在iPhone Xs 12.1操作系统中仅使用eSIM的移动国家代码。

对于"物理sim",以下代码运行良好,但在仅安装eSIM 时面临问题

CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [netInfo subscriberCellularProvider];
NSString* mcc = [carrier mobileCountryCode];

在swift中,您可以通过从eSIM获取国家代码

if #available(iOS 12.0, *) {
if let countryCode = CTTelephonyNetworkInfo().serviceSubscriberCellularProviders?.values.first(where: { $0.isoCountryCode != nil }) {
print("Country Code : (countryCode)")
}
}

注意:在iOS 12+中,使用serviceSubscriberCellularProviders。

最新更新