【问题标题】:How to make a call in iphone? [duplicate]如何在iphone中拨打电话? [复制]
【发布时间】:2012-03-21 04:58:17
【问题描述】:

可能重复:
how to make phone call by using objective c?

当我单击 tableview 行时,我正在尝试拨打电话。

但它不起作用。

这是最简洁的代码。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([indexPath row] == 0) {
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"1800-000-000"]];
}
} 

我不知道为什么它不起作用。

谁能帮我解决这个问题?

【问题讨论】:

  • if ([indexPath row] == 0) ,也可能是问题的原因。并且“1800-000-000”应该是@“tel:1800-000-000”。
  • @Hadley 我添加了“tel:1800-000-000”,但它仍然无法正常工作。可以在模拟器 r 中进行测试,否则我需要连接到设备。
  • @Sachi,很明显,你不应该在模拟器上测试,你必须在设备上测试。
  • @Sachi,你的代码说,只有点击第一行你才能打电话。注意你的 IF 语句
  • @Hadley 非常感谢。它工作正常。我还需要问一件事,你知道 OCR。

标签: iphone call


【解决方案1】:

添加电话:协议

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([indexPath row] == 0) {
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:1800-000-000"]];
}
} 

【讨论】:

  • 只是我添加了电话:协议。但它仍然无法正常工作。我需要像在android中一样给予任何许可吗? @Rahul Choudhary
  • @sachi iOS 没有权限系统。上面的东西应该可以了,尝试从数字中删除“-”并查看。
  • 不,它仍然无法正常工作。我们是否需要一个设备来测试这个。因为我在模拟器中测试。我是 iphone 开发新手。
  • 模拟器不能打电话,所以tel: URLs什么都不做。在设备上测试。
【解决方案2】:

试试这个链接我想它会帮助你 https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/PhoneLinks/PhoneLinks.html

这会起作用试试这个:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:12125551212"]];

【讨论】:

    【解决方案3】:

    试试这个

        NSString *aPhoneNo = [@"tel://" stringByAppendingString:[itsPhoneNoArray objectAtIndex:[sender tag]]] ;
        NSURL *url= [NSURL URLWithString:aPhoneNo];
        [[UIApplication sharedApplication] openURL:url];
    

    我觉得对你有帮助

    【讨论】:

      【解决方案4】:
      + (void)openPhone:(NSString *)number {
          NSString *url = [NSString stringWithFormat:@"tel://%@", number];
          [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
      } 
      

      使用它并喜欢它。

      【讨论】:

        猜你喜欢
        • 2014-12-20
        • 2011-04-03
        • 1970-01-01
        • 1970-01-01
        • 2011-04-08
        • 2011-02-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多