【问题标题】:when iPhone Xs,12.1 has only eSIM, How I can get mobileCountryCode?当 iPhone Xs,12.1 只有 eSIM 时,我如何获得 mobileCountryCode?
【发布时间】:2018-12-13 11:49:10
【问题描述】:

我没有在 iPhone Xs,12.1 OS 中找到仅使用 eSIM 的 iPhone 移动国家代码。

对于“物理 sim”,以下代码工作正常,但仅安装 eSIM 时会遇到问题

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

【问题讨论】:

  • 你能说你解决了这个问题吗?

标签: iphone telephony mobile-country-code


【解决方案1】:

您可以通过 swift 从 eSIM 中获取国家/地区代码

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

注意:从 iOS 12+ 开始,请使用subscriberCellularProvider,而不是 serviceSubscriberCellularProviders。

【讨论】:

    猜你喜欢
    • 2019-07-05
    • 1970-01-01
    • 2019-03-26
    • 2019-02-27
    • 1970-01-01
    • 1970-01-01
    • 2019-05-06
    相关资源
    最近更新 更多