iOS 拨打电话

51 篇文章 0 订阅

第一种

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]]
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值