我需要知道用户理论上是否可以调用电话。
有谁知道当用户的 iPhone 能够连接到运营商的网络时如何“返回 true”(使用 Cocoa iOS)? (不是互联网)
或者如何以编程方式告知用户有“多少个接收格”?
最佳答案
将您的应用程序链接到CoreTelephony.framework
您可以检查 CTCarrier 对象,看看是否有某些需要与电话提供商连接的属性的有效结果 (!=nil)。
例如,下面有一段代码,用于检查 CTCarrier 的 mobileNetworkCode 属性。当且仅当设备连接到电话提供商时,此属性为 != 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
关于iphone - 获取 iPhone 运营商接收状态? (不是互联网),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8892860/