【问题标题】:Making call to number mentioned in the text field拨打文本字段中提到的号码
【发布时间】:2012-03-05 07:57:19
【问题描述】:

我正在做一个生日剩余申请。在那我提供了一个文本字段来输入手机/电话号码。底部我提供了一个按钮,如果我们按下该按钮呼叫需要继续到文本字段中给出的数字。我试过但我无法做到这一点。任何人都可以帮助我编码。谢谢!

【问题讨论】:

    标签: iphone ios


    【解决方案1】:

    试试这个

        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",self._phoneNumber]];
        [[UIApplication sharedApplication] openURL:url];    
    

    仅适用于 iphone,必须实现您自己的警报委托方法。

    【讨论】:

      【解决方案2】:

      试试这个。

      -(void) makeCall{
       NSString* phoneNumber=yourTextFiled.text;//TextFiled 
       NSString *phoneNumber = [NSString stringWithFormat:@"%@",phoneNumber];
       NSURL* callUrl=[NSURL URLWithString:[NSString   stringWithFormat:@"tel:%@",phoneNumber];
       //check  Call Function available only in iphone
       if([[UIApplication sharedApplication] canOpenURL:callUrl]){
      
      [[UIApplication sharedApplication] openURL:callUrl]];
       }
       else{
      UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"ALERT" message:@"This function is only available on the iPhone"  delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
      [alert show];
      [alert release];
      }    
      }
      

      希望对你有帮助。

      【讨论】:

      • 您不应该检查设备是否是 iPhone。你可以直接调用[[UIApplication sharedApplication] canOpenURL:] 方法。如果您使用电话号码 URL 调用此方法,它将在无法拨打电话的设备上返回 NO
      • @rckoenes 是的,你是对的,但是如果我按照这种方式进行操作,请告诉我(检查设备并根据设备显示警报)。会错吗..?
      • 可能是 Apple 更改了设备名称或不返回设备名称。但是,如果有可以打电话的 iPad 怎么办?
      【解决方案3】:

      请检查这 2 个链接:

      来电号码: Programmatically Dial a Phone number and pass DTMF using the iPhone SDK

      以及为什么不从文本字段中获取价值: iPhone SDK: how to get the value of a UITextField in an alert?

      【讨论】:

        猜你喜欢
        • 2010-12-21
        • 2023-04-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-09
        相关资源
        最近更新 更多