首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在iOS 9中打开电话拨号程序?

如何在iOS 9中打开电话拨号程序?
EN

Stack Overflow用户
提问于 2016-03-04 09:43:34
回答 4查看 13.1K关注 0票数 7

我找到了解决方案,需要在info.plist中添加一些代码。我是这样做的:

代码语言:javascript
复制
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>tel</string>
</array>

还是没有帮助。我知道这个错误:

-canOpenURL: failed:"tel://4806501708“--错误:”此应用程序不允许查询方案tel“

我打开拨号程序的代码:

代码语言:javascript
复制
NSString *phoneNumber = [@"tel://" stringByAppendingString:lblVenPhoneValue.text];
if ([UIApplication.sharedApplication canOpenURL:[NSURL URLWithString:phoneNumber]]) {
        [UIApplication.sharedApplication openURL:[NSURL URLWithString:phoneNumber]];

我该怎么办?

提前谢谢

EN

回答 4

Stack Overflow用户

发布于 2016-03-04 10:54:30

你在设备上测试这个吗?,因为这在模拟器上不起作用。设备也应该有sim卡。

确认以上内容后,尝试如下

在info.plist中

代码语言:javascript
复制
<key>LSApplicationQueriesSchemes</key>
<array>
<string>tel</string>
<string>telprompt</string>
</array>

哪里要开电话拨号机?

代码语言:javascript
复制
 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",@"digits"]]]; 

代码语言:javascript
复制
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt:%@",@"digits"]]];
票数 14
EN

Stack Overflow用户

发布于 2016-03-04 10:15:13

只要把"//“从”tel://“中删除就可以了

代码语言:javascript
复制
NSString *phoneNumber = [@"tel:" stringByAppendingString:lblVenPhoneValue.text];
if ([UIApplication.sharedApplication canOpenURL:[NSURL URLWithString:phoneNumber]]) {
        [UIApplication.sharedApplication openURL:[NSURL URLWithString:phoneNumber]];

为了获得更好的检查,您可以使用

代码语言:javascript
复制
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:[NSString stringWithFormat:phoneNumber]]])
{
  CTTelephonyNetworkInfo *networkInfo = [CTTelephonyNetworkInfo new];
  CTCarrier *carrier = [networkInfo subscriberCellularProvider];
  NSString *_code = [carrier mobileNetworkCode];
  if(_code)
  {
    [[UIApplication sharedApplication] openURL:phoneNumber]];
  }
  else
  {
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"no_sim" message:@"" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
    [alert show];
  }
}
else
{
  UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"alert" message:@"alert_device_not_support" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
  [alert show];
}
票数 1
EN

Stack Overflow用户

发布于 2018-09-26 07:19:25

对于SWIFT4.0,请使用此方法(确保您不在模拟器上)

代码语言:javascript
复制
        let cleanPhoneNumber = phone.components(separatedBy: CharacterSet.decimalDigits.inverted).joined(separator: "")
        let urlString:String = "tel://\(cleanPhoneNumber)"

        if let phoneCallURL = URL(string: urlString) {
            if (UIApplication.shared.canOpenURL(phoneCallURL)) {
                UIApplication.shared.open(phoneCallURL, options: [:], completionHandler: nil)
            }
        }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35792681

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档