Friday 3 June 2011

Detect carrier information on iPhone

With the release of iOS 4, Apple introduced two new frameworks for obtaining carrier information. CTCarrier offers information about the cellular provider including the carrier name, Mobile Network Code and Mobile Carrier Code. CTTelephonyNetworkInfo is the channel to access information through CTCarrier, this class also provides an update notifier if you need to detect changes to a changes in cellular provider information, for example, if the user swaps out there SIM card.


#import <CoreTelephony/CTCarrier.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>

// Setup the Network Info and create a CTCarrier object
CTTelephonyNetworkInfo *networkInfo = [[[CTTelephonyNetworkInfo alloc] init] autorelease];
CTCarrier *carrier = [networkInfo subscriberCellularProvider];

// Get carrier name
NSString *carrierName = [carrier carrierName];
if (carrierName != nil)
  NSLog(@"Carrier: %@", carrierName);

// Get mobile country code
NSString *mcc = [carrier mobileCountryCode];
if (mcc != nil)
  NSLog(@"Mobile Country Code (MCC): %@", mcc);

// Get mobile network code
NSString *mnc = [carrier mobileNetworkCode];
if (mnc != nil)
  NSLog(@"Mobile Network Code (MNC): %@", mnc);




No comments:

Post a Comment