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

时间:2012-01-17 10:14:56

标签: iphone ios cocoa signal-strength carrier

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

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

或者如何以编程方式告诉用户有多少接收条?

1 个答案:

答案 0 :(得分:3)

将您的应用与 CoreTelephony.framework

相关联

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

例如,下面有一段代码可以检查 CTCarrier mobileNetworkCode 属性。此属性为!​​= nil if-and-only-如果设备连接到电话提供商(您所需的任务,能够拨打电话的用户,包含在上述状态中)。

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 Developer Documentation网址的更多信息:http://developer.apple.com/library/IOs/#documentation/NetworkingInternet/Reference/CTCarrier/Reference/Reference.html