50

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.

mfaani
  • 33,269
  • 19
  • 164
  • 293
thierryb
  • 3,660
  • 4
  • 42
  • 58
  • 5
    What, you mean there are iPhone carriers other than AT&T? – Joel Coehoorn May 12 '09 at 15:49
  • Are you talking about who's service the phone is currently connected to (i.e. might be roaming), or who is the carrier you get bills from? – crashmstr May 12 '09 at 15:54
  • 15
    You might not have heard of it, but there are other countries in the world. And interestingly, they do have mobile technology. – mentat May 12 '09 at 15:56
  • 4
    Again - have a sense of humor folks. – Shane C. Mason May 12 '09 at 15:58
  • The only mechanism to detect if you are roaming is through reading an undocumented system file [See previous question](http://stackoverflow.com/questions/900547/is-there-any-way-to-determine-if-the-iphone-is-roaming) which is against the Apple rules – joneswah Jan 10 '12 at 00:17

11 Answers11

84

In iOS 4, the CoreTelephony framework is useable, here's a snippet to get the carrier name:

CTTelephonyNetworkInfo *netinfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [netinfo subscriberCellularProvider];
NSLog(@"Carrier Name: %@", [carrier carrierName]);
[netinfo release];

Link against CoreTelephony and include in your headers:

#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <CoreTelephony/CTCarrier.h>
BadPirate
  • 25,802
  • 10
  • 92
  • 123
George Zhu
  • 1,011
  • 8
  • 7
  • 13
    According to Apple's documentation, this always give you info about your honme carrier, not the carrier you're currently connected to when roaming. – phoenies Aug 05 '11 at 14:28
  • for carrier name, it's just "Carrier", not something like verizon, ... . – Jafar Khoshtabiat Oct 17 '19 at 07:22
  • Now CTCarrier is deprecated. https://developer.apple.com/documentation/coretelephony/ctcarrier . I am wondering what would be the alternative approach for this? I don't find alternative API for this. – Rohit Singh Aug 10 '22 at 15:57
  • @RohitSingh Could it be CTTelephonyNetworkInfo .serviceSubscriberCellularProviders? That returns a dict of CTCarrier and is not deprecated... https://developer.apple.com/documentation/coretelephony/cttelephonynetworkinfo/3024511-servicesubscribercellularprovide – Michael Apr 06 '23 at 04:51
15

Just to make a note here.. I tested this API on different SIMs and it seems that the name of the operator the iPhone is locked to is returned with [carrer carrierName]!!

I tested this on 2 iphones, one locked and the other not, and for the locked one, regardless of the SIM provider, it returns the name of the operator it is locked to everytime i run my test app. Note however that the MNC does change!

Abolfoooud
  • 2,663
  • 2
  • 27
  • 27
  • 1
    Good comment. Was not aware of this until I saw this reply. Can confirm I am getting the same behaviour - the carrierName returns the locked carrier name, not the SIM carrier. – Ian L Sep 25 '12 at 15:39
  • Tested on iOS 7, unlocked phone: always returns "Carrier" as carrierName. So it is not possible to correctly figure out which operator is in the phone. The string returned is equal to string displayed in Settings -> General -> About under Carrier. The version number is lost, however. – Legoless Jul 29 '13 at 20:45
  • This is correct. MNC is the only accurate test of carrier from CTCarrier. We cache MNC value as well, as it will return nil if the user has no network connection, is in airplane mode, or has removed their SIM. – NSAlexC Feb 25 '14 at 19:26
4

For swift users you can try this:

import CoreTelephony

static var carrierName:String? {
    let networkInfo = CTTelephonyNetworkInfo()
    let carrier = networkInfo.subscriberCellularProvider
    return carrier?.carrierName
}
Sanif SS
  • 602
  • 5
  • 18
  • carrier?.carrierName not exists currently – Markus Apr 02 '19 at 09:34
  • Currently exists carrier?.description – Markus Apr 02 '19 at 09:35
  • The output of carrier?.description: [\"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] – Markus Apr 02 '19 at 09:37
4

CTCarrier, carrierName and other info is deprecated as of iOS 16 with no replacement: https://developer.apple.com/documentation/coretelephony/ctcarrier.

Miroslav Kovac
  • 1,168
  • 1
  • 16
  • 27
2

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.

Jason Harwig
  • 43,743
  • 5
  • 43
  • 44
1

While developing Alpha, I encountered the same problem. The project itself was not limited to use only public API, so first I tried @Jason Harwig's solution. Because I could not get it to work, I thought of another option.

My solution uses private API to access the _serviceString ivar of the label (UIStatusBarServiceItemView) that is displayed in status bar.

It relies on status bar having a carrier value and only needs UIKit to work.

- (NSString *)carrierName
{
    UIView* statusBar = [self statusBar];

    UIView* statusBarForegroundView = nil;

    for (UIView* view in statusBar.subviews)
    {
        if ([view isKindOfClass:NSClassFromString(@"UIStatusBarForegroundView")])
        {
            statusBarForegroundView = view;
            break;
        }
    }

    UIView* statusBarServiceItem = nil;

    for (UIView* view in statusBarForegroundView.subviews)
    {
        if ([view isKindOfClass:NSClassFromString(@"UIStatusBarServiceItemView")])
        {
            statusBarServiceItem = view;
            break;
        }
    }

    if (statusBarServiceItem)
    {
        id value = [statusBarServiceItem valueForKey:@"_serviceString"];

        if ([value isKindOfClass:[NSString class]])
        {
            return (NSString *)value;
        }
    }

    return @"Unavailable";
}

- (UIView *)statusBar
{
    NSString *statusBarString = [NSString stringWithFormat:@"%@ar", @"_statusB"];
    return [[UIApplication sharedApplication] valueForKey:statusBarString];
}

I only tested the method with applications that have status bar visible. It returns the same string as it is displayed in status bar, so it works correctly even when roaming.

This method is not App Store safe.

Legoless
  • 10,942
  • 7
  • 48
  • 68
1

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
}
codethemall
  • 144
  • 1
  • 5
1

for Swift and ios 12.0 < do the following:

import CoreTelephony

static var carrierName:String? {
    CTTelephonyNetworkInfo().serviceSubscriberCellularProviders?.first?.value.carrierName ?? ""
}
Bary Levy
  • 584
  • 5
  • 6
0

https://developer.apple.com/iphone/prerelease/library/documentation/NetworkingInternet/Reference/CTCarrier/Reference/Reference.html#//apple_ref/doc/uid/TP40009596-CH1-DontLinkElementID_3

There is a such way however it's only available on iOS 4 so you won't be able to use it on previous versions. And this probably breaks your backward compatibility too.

radalin
  • 600
  • 5
  • 13
0

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.

Markus
  • 1,147
  • 16
  • 26
0

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.

mfaani
  • 33,269
  • 19
  • 164
  • 293