iOS 我无法获取我的运营商名称

发布于 2024-12-15 16:04:07 字数 559 浏览 5 评论 0原文

正如这里所解释的 -> 以编程方式从 iPhone 检索运营商名称

我正在尝试获取我的运营商名称,我正在使用此代码

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

,但我收到了关于 [Carrier CarrierName] 的警告:找不到实例方法“-CarrierName”

,我已将 Coretelephony 框架添加到我的项目中,但是当我执行我的应用程序它崩溃了!

感谢大家!

as explained here -> Retrieving Carrier Name from iPhone Programmatically

i'm trying to get my carrier's name, i'm using this code

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

but i receive a warning on [carrier carrierName]: Instance method '-carrierName' not found

i've added and the framework coretelephony to my project but when i execute my app it crashes!

thanks to all!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

比忠 2024-12-22 16:04:07

您是否明确导入了 CTCarrier?

#import <CoreTelephony/CTCarrier.h>

Did you explicitly import CTCarrier?

#import <CoreTelephony/CTCarrier.h>
回忆那么伤 2024-12-22 16:04:07

我也有同样的问题,并尝试通过设备登录:

NSLog(@"carrierName = %@",carrier.carrierName);
NSLog(@"mobileCountryCode = %@",carrier.mobileCountryCode);
NSLog(@"mobileNetworkCode = %@",carrier.mobileNetworkCode);
NSLog(@"isoCountryCode = %@",carrier.isoCountryCode);
NSLog(@"allowVOIP = %d",carrier.allowsVOIP);

结果:

2012-05-29 11:48:31.466 CarrierTest[357:707] mobileCountryCode = 466

2012-05-29 11:48:31.469 CarrierTest[357:707]移动网络代码 = 97

2012-05-29 11:48:31.470载体测试[357:707] isoCountryCode = tw

2012-05-29 11:48:31.472载体测试[357:707]allowVOIP = 1

对象载体名称是“.....”在运行堆栈中,实际上它应该是“台湾大哥大”,

似乎是字符串编码问题,因为我无法获取它?我不知道...

你可以尝试其他运营商的 SIM 卡。

I have same problem too,and try to log by device:

NSLog(@"carrierName = %@",carrier.carrierName);
NSLog(@"mobileCountryCode = %@",carrier.mobileCountryCode);
NSLog(@"mobileNetworkCode = %@",carrier.mobileNetworkCode);
NSLog(@"isoCountryCode = %@",carrier.isoCountryCode);
NSLog(@"allowVOIP = %d",carrier.allowsVOIP);

result:

2012-05-29 11:48:31.466 carrierTest[357:707] mobileCountryCode = 466

2012-05-29 11:48:31.469 carrierTest[357:707] mobileNetworkCode = 97

2012-05-29 11:48:31.470 carrierTest[357:707] isoCountryCode = tw

2012-05-29 11:48:31.472 carrierTest[357:707] allowVOIP = 1

the object carrierName is "....." in run stack,actually it should be "台湾大哥大"

it seem like string encoding problem cause i can't get it? I have no idea...

you can try the other carrier SIM card.

三生一梦 2024-12-22 16:04:07

尝试

NSLog(@"Carrier Name: %@", carrier.carrierName);

一下。

Try

NSLog(@"Carrier Name: %@", carrier.carrierName);

instead.

殊姿 2024-12-22 16:04:07

在 Swift 5 中是这样的

第一张 SIM 卡为 0000000100000001

如果手机有 2 张 SIM 卡,则第二张 SIM 卡为 0000000100000002

import CoreTelephony

let networkInfo = CTTelephonyNetworkInfo()

var cc: String = ""
var mnc: String = ""
var mcc: String = ""
var cn: String = ""

if let providers = networkInfo.serviceSubscriberCellularProviders, let carrier = providers["0000000100000001"]{
            cc  = carrier.isoCountryCode ?? ""
            mnc = carrier.mobileNetworkCode ?? ""
            mcc = carrier.mobileCountryCode ?? ""
            cn =  carrier.carrierName ?? ""
 }

In Swift 5 like this

0000000100000001 for first sim

0000000100000002 for secound sim if mobile has 2 sim cards

import CoreTelephony

let networkInfo = CTTelephonyNetworkInfo()

var cc: String = ""
var mnc: String = ""
var mcc: String = ""
var cn: String = ""

if let providers = networkInfo.serviceSubscriberCellularProviders, let carrier = providers["0000000100000001"]{
            cc  = carrier.isoCountryCode ?? ""
            mnc = carrier.mobileNetworkCode ?? ""
            mcc = carrier.mobileCountryCode ?? ""
            cn =  carrier.carrierName ?? ""
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文