iOS拨打电话的3种方式

本文介绍了在iOS中拨打电话的三种方法,包括使用openURL(telprompt)方法(可能引发App Store审核问题),openURL(tel)方法(在iOS 10.2之前无弹框,需手动处理)及其Swift实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

iOS实现拨打电话的方式:

方法一、requestWithURL,此方法拨打前弹出提示

NSMutableString * string = [[ NSMutableString alloc] initWithFormat: @"tel:%@", @"136****0000"];
UIWebView * callWebview = [[ UIWebView alloc] init];
[callWebview loadRequest:[ NSURLRequest requestWithURL:[ NSURL URLWithString:string]]];
[ self.view addSubview:callWebview];

swift代码:

let callWebview = UIWebView()callWebview.loadRequest( NSURLRequest(url: URL(string: "tel:136****0000")!) as URLRequest)
self.view.addSubview(callWebview)


方法二、openURL(telprompt) ,此方法拨打前弹出提示,据说会导致App Store审核不通过

NSMutableString * string = [[ NSMutableString alloc] initWithFormat: @"telprompt:%@", @"136****0000"];
[[ UIApplication sharedApplication] openURL:[ NSURL URLWithString:string]];

swift代码:

UIApplication.shared.openURL(URL(string: "telprompt:136****0000")!)


方法三、利用openURL(tel),此方法在iOS 10.2之前不会添加弹框,需要自己处理,手动添加alert即可

NSMutableString * string = [[ NSMutableString alloc] initWithFormat: @"tel:%@", @"136****0000"];
[[ UIApplication sharedApplication] openURL:[ NSURL URLWithString:string]];

swift代码:

UIApplication.shared.openURL(URL(string: "tel:136****0000")!)




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值