Getting carrier's name with CoreTelephony returns just “Carrier”

六眼飞鱼酱① 提交于 2019-12-23 07:26:40

问题


I tried getting carrier name with this code (using CoreTelephony):

CTTelephonyNetworkInfo *netinfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [netinfo subscriberCellularProvider];
NSLog(@"Carrier Name: %@", [carrier carrierName]);

It returns "Carrier". If i go to iPhone settings my carrier's name is correct there. My iOS on the phone is v4.2.1.

What am i doing wrong?


回答1:


Do you really get string "Carrier" or is the string empty? Documentation says:

The value for this property is nil if any of the following apply:

The device is in Airplane mode. There is no SIM card in the device. The device is outside of cellular service range.

Bet it's empty also in simulator.

Anyway, you should be checking mobileNetworkCode, since names are rarely correct (at least in Europe, where operators come and go changing their names quite often).




回答2:


by this, you can get mobile Network code, mobile country code . from these values you can specify which sim name is this.

CTTelephonyNetworkInfo* info = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier* carrier = info.subscriberCellularProvider;
NSString *mobileCountryCode = carrier.mobileCountryCode;
NSString *carrierName = carrier.carrierName;
NSString *isoCountryCode = carrier.isoCountryCode;
NSString *mobileNetworkCode = carrier.mobileNetworkCode;

and you can make web service for this to specify which carrier name of the network, this parameter belongs to. these parameters can be uniquely identified from this wikipedia.

for example, my country code is "410", my carrier network is "06" and it correctly identifies my carrier name.

I was also stuck at the same issue and now solved



来源:https://stackoverflow.com/questions/6055835/getting-carriers-name-with-coretelephony-returns-just-carrier

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!