Mac*_*ieł 31 objective-c ipad ios ios8
在iOS <8,您可以使用功能- (BOOL)canOpenURL:(NSURL *)url.
在iOS 8上,此功能YES即使在iPad上也会返回.我猜它与通过wi-fi(或其他新功能)通话有关,但我的iPad无法拨打电话.任何人都知道检测该功能的更好方法吗?
Mil*_*hah 16
好的,所以我刚遇到同样的问题.似乎iPad和iPod为canOpenURL方法返回YES值.请看下面的答案,因为这对我有用.我有一个自定义集合视图单元格,这就是为什么这个代码在我的awakeFromNib文件中.但是,您应该在该特定viewController的ViewDidLoad中编写此代码.
确保在项目中包含"CoreTelephony.Framework".
在视图控制器中包含以下文件:
#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.
}
}
Run Code Online (Sandbox Code Playgroud)
Wap*_*iti -4
你可以看看它是否是iPhone。并且可能将其与 结合使用- (BOOL)canOpenURL:(NSURL *)url。这样您就可以避开那些显然无法拨打手机的设备。
if ([[[UIDevice currentDevice] model] isEqualToString:@"iPhone"] ) {
// Make Phone Call
}
Run Code Online (Sandbox Code Playgroud)