iOS 拨打电话四种方式总结(推荐最后一种)

方法一:不弹出提示直接拨打

NSMutableString *str=[[NSMutableStringalloc]initWithFormat:@"tel:%@",@"电话号码"];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

方法二:会弹出提示

NSMutableString *str=[[NSMutableStringalloc]initWithFormat:@"tel:%@",@"电话号码"];

UIWebView *callWebview = [[UIWebViewalloc]init];

[callWebviewloadRequest:[NSURLRequestrequestWithURL:[NSURLURLWithString:str]]];

[self.view addSubview:callWebview];

方法三:会弹出提示

NSMutableString* str=[[NSMutableString alloc]initWithFormat:@"telprompt://%@",@"111"];

        

 [[UIApplication sharedApplication]openURL:[NSURL URLWithString:str]];

以上是正常的三种拨号方式,会有卡顿,网络上好多都是这种答案。

博主机智的想到了如何不让其卡顿,用户体验完美的方案:

方案四之终极拨号方式:

NSMutableString *str=[[NSMutableString alloc]initWithFormat:@"tel:%@“,@“114”];

        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:tel preferredStyle:UIAlertControllerStyleAlert];

        

        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {

            

        }];

        

        UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"呼叫" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

        }];

        

        // Add the actions.

        [alertController addAction:cancelAction];

        [alertController addAction:otherAction];

        [self presentViewController:alertController animated:YES completion:nil];

如果帮到了你,记得朝着北京海淀西二旗的方向默默的心里喊一声:谢谢博主!

评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值