Retrieving Carrier Name from iPhone programmatically

Viewed 36341

Is there a way to know the cell carrier on an iPhone programmatically?

I am looking for the carrier name which the iPhone is connected to.

10 Answers

There is no public API for getting the carrier name. If you don't need to publish on the App Store you could look at using private api's.

VVCarrierParameters.h in the VisualVoiceMail package seems to have a carrierServiceName class method that might be what you need. Drop that header in your project and call [VVCarrierParameters carrierServiceName].

Note your app will most likely be rejected if you do this.

Get carrier name from status bar in case if Core Telephony returns "Carrier"

func getCarrierName() -> String? {

    var carrierName: String?

    let typeName: (Any) -> String = { String(describing: type(of: $0)) }

    let statusBar = UIApplication.shared.value(forKey: "_statusBar") as! UIView

    for statusBarForegroundView in statusBar.subviews {
        if typeName(statusBarForegroundView) == "UIStatusBarForegroundView" {
            for statusBarItem in statusBarForegroundView.subviews {
                if typeName(statusBarItem) == "UIStatusBarServiceItemView" {
                    carrierName = (statusBarItem.value(forKey: "_serviceString") as! String)
                }
            }
        }
    }
    return carrierName
}

for Swift and ios 12.0 < do the following:

import CoreTelephony

static var carrierName:String? {
    CTTelephonyNetworkInfo().serviceSubscriberCellularProviders?.first?.value.carrierName ?? ""
}

When you print output of carrier?.description

This is what you see:

[\"0000000100000001\": CTCarrier (0x2803a1980) {\n\tCarrier name: [Vodafone]\n\tMobile Country Code: [214]\n\tMobile Network Code:[01]\n\tISO Country Code:[es]\n\tAllows VOIP? [YES]\n}\n]

Formatted (\n and \t):

[\"0000000100000001\": CTCarrier (0x2803a1980) {
    Carrier name: [Vodafone]
    Mobile Country Code: [214]
    Mobile Network Code:[01]
    ISO Country Code:[es]
    Allows VOIP? [YES]
}
]

So get carrier name from status bar is a good option (at least for me)

I mean the answer of "codethemall" user.

More of an important comment. Just to add docs about the carrierName:

The carrier provides this string, formatting it for presentation to the user. The value does not change if the user is roaming; it always represents the provider with which the user has an account.

If you configure a device for a carrier and then remove the SIM card, this property retains the name of the carrier. If you then install a new SIM card, its carrier name replaces the previous value of this property.

The value for this property is nil if the user never configured a carrier for the device.

Related