第一种
NSString *phoneStr = [NSString stringWithFormat:@"tel://%@",phone];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0) {//设备系统为IOS 10.0或者以上的[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneStr] options:@{} completionHandler:nil];
}else{//设备系统为IOS 10.0以下的[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneStr]];
if (@available(iOS 10.0, *)) {//设备系统为IOS 10.0或者以上的[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneStr] options:@{} completionHandler:nil];
} else {[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneStr]];
}
第二种
NSString *phoneStr = [NSString stringWithFormat:@"tel:%@",phone];
UIWebView * callWebview = [[UIWebView alloc] init];
[callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:phoneStr]]];
[self.view addSubview:callWebview];
但是 webView
已经不能使用了,要换 WKWebView
第一步
#import <WebKit/WebKit.h>@interface ViewController ()<WKNavigationDelegate>
第二步
WKWebView *webView = [WKWebView new];
webView.navigationDelegate = self;
NSString *phoneStr = [NSString stringWithFormat:@"tel:%@",self.model.store.contactPhone];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:phoneStr]]];
[self.view addSubview:webView];
第三步
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {NSURL *URL = navigationAction.request.URL;NSString *scheme = [URL scheme];UIApplication *app = [UIApplication sharedApplication];// 打电话if ([scheme isEqualToString:@"tel"]) {if ([app canOpenURL:URL]) {[app openURL:URL];// 一定要加上这句,否则会打开新页面decisionHandler(WKNavigationActionPolicyCancel);return;}}decisionHandler(WKNavigationActionPolicyAllow);
}
第三种
NSString *telephoneNumber=@"拨打的号码";
NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",telephoneNumber];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]]