CoreTelephony framework contains routines for accessing telephony-related information (available since iOS 4.0, more information here). CTCarrier class allows you to get some useful information about the user’s home cellular service provider. Let’s use it to get carrier name.
First method will check if CTTelephonyNetworkInfo class is available and will return CTCarrier instance on success.
+ (CTCarrier *) carrier {
if (NSClassFromString(@"CTTelephonyNetworkInfo") == nil) {
return nil;
}
CTTelephonyNetworkInfo *netinfo = [ [ [CTTelephonyNetworkInfo alloc] init] autorelease];
CTCarrier *carrier = [netinfo subscriberCellularProvider];
return carrier;
}
Second method will return carrier name or “Unavailable” string if carrier is not available.
+ (NSString *) carrierName {
CTCarrier *carrier = [self carrier];
if (carrier == nil) {
return @"Unavailable";
}
return carrier.carrierName;
}
Discover more from CODE t!ps
Subscribe to get the latest posts sent to your email.