可以獲取到手機(jī)的運(yùn)營商别凤,但是獲取不到本機(jī)手機(jī)號碼~
#import <SystemConfiguration/CaptiveNetwork.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <CoreTelephony/CTCarrier.h>
- (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 = @"";
}
//網(wǎng)絡(luò)供應(yīng)商編碼
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; //網(wǎng)絡(luò)運(yùn)營商的名字
NSString *code = [carrier mobileNetworkCode];
if ([code isEqualToString:@"00"] || [code isEqualToString:@"02"] || [code isEqualToString:@"07"]) {
// ret = @"移動(dòng)"
carrier_name = @"CMCC";
}
if ([code isEqualToString:@"03"] || [code isEqualToString:@"05"]) {
// ret = @"電信";
carrier_name = @"CTCC";
}
if ([code isEqualToString:@"01"] || [code isEqualToString:@"06"]) {
// ret = @"聯(lián)通";
carrier_name = @"CUCC";
}
if (code == nil) {
carrier_name = @"";
}
carrier_name = [NSString stringWithFormat:@"%@-%@",carrier_name,[carrier.carrierName stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"運(yùn)營商:%@", carrier_name);
}
慢慢來饰序,一步一個(gè)巴掌印。规哪。求豫。。诉稍。