1.导入头文件
#import<CoreTelephony/CTTelephonyNetworkInfo.h>
#import<CoreTelephony/CTCarrier.h>
2.返回运营商的名称
+ (NSString*)checkCarrier{
NSString *ret = [[NSString alloc] init];
CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [info subscriberCellularProvider];
if( carrier ==nil)
{
return(@"0");
}
NSString *code = [carrier mobileNetworkCode];
if([code isEqualToString:@""])
{
return(@"0");
}
if( [code isEqualToString:@"00"] || [code isEqualToString:@"02"] || [code isEqualToString:@"07"] )
{
ret =@"移动";
}
if( [code isEqualToString:@"01"] || [code isEqualToString:@"06"] )
{
ret =@"联通";
}
if( [code isEqualToString:@"03"] || [code isEqualToString:@"05"] )
{
ret =@"电信";;
}
return ret;
}
网友评论