【问题标题】:how to open phone dialler in iOS 9?如何在 iOS 9 中打开电话拨号器?
【发布时间】:2016-03-04 09:43:34
【问题描述】:

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

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>tel</string>
</array>

仍然没有帮助。 我收到此错误:

"-canOpenURL:URL 失败:"tel://4806501708" - 错误:"这 不允许app查询方案tel”

我打开拨号器的代码:

NSString *phoneNumber = [@"tel://" stringByAppendingString:lblVenPhoneValue.text];
if ([UIApplication.sharedApplication canOpenURL:[NSURL URLWithString:phoneNumber]]) {
        [UIApplication.sharedApplication openURL:[NSURL URLWithString:phoneNumber]];

我需要做什么?
提前致谢

【问题讨论】:

  • [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",@"digits"]]];试试这个,没有“//”
  • NSString *phoneNumber = [@"telprompt://" stringByAppendingString:@number]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];如果上述方法不起作用,请也检查一下
  • 运气不好。仍然得到:“此应用不允许查询方案 telprompt”
  • 我的 info.plist 是否正确?在这里
  • telprompt 在 info.plist 中试试这个

标签: ios objective-c iphone ios9 openurl


【解决方案1】:

你是在设备上测试这个吗? ,因为这不适用于模拟器。而且设备也应该有sim卡。

以上确认后尝试关注

在 info.plist 中

<key>LSApplicationQueriesSchemes</key>
<array>
<string>tel</string>
<string>telprompt</string>
</array>

想在哪里打开电话拨号器

 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",@"digits"]]]; 

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt:%@",@"digits"]]];

【讨论】:

  • 不添加 LSApplicationQueriesSchemes 也可以正常工作
【解决方案2】:

只需从 @"tel://" 中删除 "//" 就可以了

NSString *phoneNumber = [@"tel:" stringByAppendingString:lblVenPhoneValue.text];
if ([UIApplication.sharedApplication canOpenURL:[NSURL URLWithString:phoneNumber]]) {
        [UIApplication.sharedApplication openURL:[NSURL URLWithString:phoneNumber]];

您可以使用更好的检查

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];
}

【讨论】:

  • 我忘了说我用的是模拟器。也许这就是失败的原因。我应该检查设备。
  • 哦。这应该是原因,那么你应该为这种情况添加检查/警报
【解决方案3】:

对于 Swift 4.0 使用这个(确保你不在模拟器上)

        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)
            }
        }

【讨论】:

    【解决方案4】:

    这在模拟器中不起作用,但在 iPhone 设备中可以正常工作。

    私有函数 makeCall(number:String){ 让数字=“9876543210”

        if let url = URL(string: "tel://\(number)"), UIApplication.shared.canOpenURL(url) {
            if #available(iOS 10, *) {
                UIApplication.shared.open(url)
            } else {
                UIApplication.shared.openURL(url)
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2014-09-27
      • 1970-01-01
      • 2010-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多