iOS 获取手机运营商

可以获取到手机的运营商,但是获取不到本机手机号码~

#import 
#import 
#import 

- (void)getSIMOperator {

    CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
    CTCarrier *carrier = networkInfo.subscriberCellularProvider;
    NSString *carrier_country_code = carrier.isoCountryCode;

    if (carrier_country_code == nil) {
        carrier_country_code = @"";
    }
    //国家编号
    NSString *CountryCode = carrier.mobileCountryCode;

    if (CountryCode == nil) {
        CountryCode = @"";
    }
    //网络供应商编码
    NSString *NetworkCode = carrier.mobileNetworkCode;

    if (NetworkCode == nil) {
        NetworkCode = @"";
    }

    NSString *mobile_country_code = [NSString stringWithFormat:@"%@%@",CountryCode,NetworkCode];

    if (mobile_country_code == nil) {
        mobile_country_code = @"";
    }

    NSString *carrier_name = nil;    //网络运营商的名字
    NSString *code = [carrier mobileNetworkCode];

    if ([code isEqualToString:@"00"] || [code isEqualToString:@"02"] || [code isEqualToString:@"07"]) {
        // ret = @"移动"
        carrier_name = @"CMCC";
      }
  
    if ([code isEqualToString:@"03"] || [code isEqualToString:@"05"]) {
        // ret = @"电信";
        carrier_name =  @"CTCC";
    }

    if ([code isEqualToString:@"01"] || [code isEqualToString:@"06"]) {
        // ret = @"联通";
        carrier_name =  @"CUCC";
    }
  
    if (code == nil) {
        carrier_name = @"";
    }

    carrier_name = [NSString stringWithFormat:@"%@-%@",carrier_name,[carrier.carrierName stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    NSLog(@"运营商:%@", carrier_name);
}

慢慢来,一步一个巴掌印。。。。。

你可能感兴趣的:(iOS 获取手机运营商)