获取 iPhone 运营商接收状态? (不是互联网)

发布于 2024-12-27 13:10:12 字数 124 浏览 1 评论 0原文

我需要知道用户理论上是否可以打电话。

有谁知道当用户的iPhone能够连接到运营商的网络时如何“返回true”(使用Cocoa iOS)? (不是互联网)

或者如何以编程方式告诉用户“有多少个接收格”?

I need to know if the user could theoretically make a phone call.

Does anyone know how to "return true" (using Cocoa iOS) when the user's iPhone is able to connect to the carrier's network? (not the internet)

Or how to programmatically tell "how many bars of reception" the user has?

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

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

发布评论

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

评论(1

本宫微胖 2025-01-03 13:10:13

将您的应用程序链接到 CoreTelephony.framework

您可以检查 CTCarrier 对象并查看对于需要连接的某些属性是否有有效结果 (!=nil)电话提供商。

例如,下面有一段代码,用于检查 CTCarriermobileNetworkCode 属性。当且仅当设备连接到电话提供商时,此属性为 != nil(您所需的任务,即用户能够拨打电话,包含在上述状态中)。

CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [netInfo subscriberCellularProvider];

//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.
NSString *mnc = [carrier mobileNetworkCode]; 

if(!mnc) {
    //if we're here, than probably we're disconnected from the Phone Provider
}

netInfo.subscriberCellularProviderDidUpdateNotifier = ^ (CTCarrier * carrier) {
    //this block is executed each time we've a change to the state of the carrier
    //be sure to check the carrier object, in order to see is we're connected to a
    //phone provider.

};

更多信息请参见 Apple 开发者文档网址: http ://developer.apple.com/library/IOs/#documentation/NetworkingInternet/Reference/CTCarrier/Reference/Reference.html

Link your application against the CoreTelephony.framework

You can check the CTCarrier object and see if you've a valid result (!=nil) for some property that require a connection with the Phone Provider.

For example, below there's a snip of code that check against the mobileNetworkCode property of CTCarrier. This property is != nil if-and-only-if the device is connected to a Phone Provider (your desired task, user able to make a phone call, is included in the state described above).

CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [netInfo subscriberCellularProvider];

//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.
NSString *mnc = [carrier mobileNetworkCode]; 

if(!mnc) {
    //if we're here, than probably we're disconnected from the Phone Provider
}

netInfo.subscriberCellularProviderDidUpdateNotifier = ^ (CTCarrier * carrier) {
    //this block is executed each time we've a change to the state of the carrier
    //be sure to check the carrier object, in order to see is we're connected to a
    //phone provider.

};

more info at the Apple Developer Documentation url: http://developer.apple.com/library/IOs/#documentation/NetworkingInternet/Reference/CTCarrier/Reference/Reference.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文