5

How to get the currently using operator details (like Airtel or Idea or etc..)of iPhone.

Is it possible to get those details or is there any way to identify which operator currently we are using.I am developing an application which is based on the operator, if user changes his SIM(Operator) then the app shouldn't work, it has to work for that particular operator.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Shiva Reddy
  • 456
  • 1
  • 7
  • 26
  • possible duplicate of [Retreiving Carrier Name from iPhone Programmatically](http://stackoverflow.com/questions/853467/retreiving-carrier-name-from-iphone-programmatically) – Brad Larson May 19 '11 at 17:25

3 Answers3

12

CTCarrier should have the info you need in it.

Edit: CTTelephonyNetworkInfo responds to a user switching SIMs mid-session, and provides an instance of CTCarrier for you.

Sample code (in your app delegate):

#import <CoreTelephony/CoreTelephony.h>

static NSString *requiredCarrier = @"Verizon"; // example carrier

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  CTTelephonyNetworkInfo *myNetworkInfo = [[CTTelephonyNetworkInfo alloc] init];
  CTCarrier *myCarrier = [myNetworkInfo subscriberCellularProvider];

  if(![[myCarrier carrierName] isEqualToString:requiredCarrier])
  {
    // lock the app, possibly terminate the app after displaying a UIAlertView
    // informing the user of the network-lock.
  }

  // ...
  return YES;
}

Note the following advisory on the properties of CTCarrier (I would recommend not doing a permanent one-way lock if a nil carrier is read):

"The value for this property is nil if any of the following apply:

  • The device is in Airplane mode.
  • There is no SIM card in the device.
  • The device is outside of cellular service range."

Of the properties of CTCarrier to validate on, I would recommend carrierName specifically as it doesn't change when the user is roaming so the app will still work as long as the SIM is tied to your desired operator.

1

Just a quick note in case someone is looking for this. I have noticed from playing with the CTCarrier API that "nil" is returned to any of its properties only on the emulator. On the device it returns @"" (blank string) for some reason! Checking agains nil failed ont eh device but checking equality with @"" worked!

Abolfoooud
  • 2,663
  • 2
  • 27
  • 27
0

You can use the Core Telephony framework to achieve this. In particular CTCarrier and the carrierName property. View the documentation here: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Reference/CTCarrier/Reference/Reference.html%23//apple_ref/doc/uid/TP40009596

lxt
  • 31,146
  • 5
  • 78
  • 83