在 iOS <8 上,您可以使用函数 - (BOOL)canOpenURL:(NSURL *)url
。
在 iOS 8 上,此函数返回 YES
,即使在 iPad 上也是如此。我猜它与通过 Wi-Fi 调用(或其他新功能)有关,但我的 iPad 无法调用电话。有人知道检测该功能的更好方法吗?
最佳答案
好的,所以我刚遇到同样的问题。似乎 iPad 和 iPod 对 canOpenURL 方法返回 YES 值。请在下面查看我的回答,因为这对我有用。我有一个自定义 Collection View 单元格,这就是我的 awakeFromNib 文件中有这段代码的原因。但是,您应该在该特定 viewController 的 ViewDidLoad 中编写此代码。
确保在您的项目中包含“CoreTelephony.Framework”。
在 View Controller 中包含以下文件:
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <CoreTelephony/CTCarrier.h>
- (void)awakeFromNib {
// Initialization code
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel://"]]) {
// Check if iOS Device supports phone calls
CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [netInfo subscriberCellularProvider];
NSString *mnc = [carrier mobileNetworkCode];
// User will get an alert error when they will try to make a phone call in airplane mode.
if (([mnc length] == 0)) {
// Device cannot place a call at this time. SIM might be removed.
} else {
// iOS Device is capable for making calls
}
} else {
// iOS Device is not capable for making calls
}
if ( ! [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"sms:"]]) {
// iOS Device is not capable to send SMS messages.
}
}
关于ios - 如何检查设备是否可以调用电话(iOS 8)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25873240/