【问题标题】:Make calls from iPhone app [duplicate]从 iPhone 应用程序拨打电话 [重复]
【发布时间】:2012-04-01 16:30:27
【问题描述】:

可能重复:
make a call in iphone from my application

我想通过我的 iPhone 应用程序拨打给定号码的电话。你能推荐任何能最好地解释它的好教程或告诉我这个过程吗?

【问题讨论】:

标签: iphone ios call


【解决方案1】:
NSString* phoneNumber=TextFiled Name
    NSString *number = [NSString stringWithFormat:@"%@",phoneNumber];
    NSURL* callUrl=[NSURL URLWithString:[NSString   stringWithFormat:@"tel:%@",number]];

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

【讨论】:

  • 我还建议检查电话号码格式并清除空格(如果有)。
【解决方案2】:

有两种方法可以实现:-

1) [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://9912345678"]];

2) 您可以使用UITextView 并启用电话检测。之后,电话号码将看起来像超链接。使用以下代码。

mytextview.text = @"9943586256";
mytextview.dataDetectorTypes = UIDataDetectorTypePhoneNumber;
mytextview.editable=NO;

如果您想在自定义表格视图单元格中显示电话号码,这很有帮助。

由于某些项目的要求,我个人喜欢第二个。当我在UITextView 中提供电话号码并按下时将开始通话。

【讨论】:

    【解决方案3】:

    从另一个应用程序中打开一个应用程序在 iOS 中通过“url 方案”机制进行管理。如果一个应用程序定义了一个 url 方案,并且这个方案是公共的,那么您可以使用它来运行该应用程序。 基本规则是首先检查您的设备是否支持该方案(例如,您无法在 iPad 上拨打电话,因为未安装电话应用程序),然后,如果答案是肯定的,请致电:

    
    if([[UIApplication sharedApplication] canOpenURL:myURL]) {
      [[UIApplication sharedApplication] openURL:myURL];
    } else {
      // do something else, e.g. inform the user that he/she cannot open the app
    }
    

    此检查对于某些方案很重要,例如电话一,系统检查网址是否格式正确。例如:电话号码不支持数字之间的空格。

    此处描述了最常见的 Apple URL 方案: http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/PhoneLinks.html#//apple_ref/doc/uid/TP40007893-SW1 特别是电话网址方案在这里: http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/PhoneLinks.html#//apple_ref/doc/uid/TP40007893-SW1

    终于有一个名为handleOpenURL 的网站正在尝试收集所有应用程序的url 方案。如果您定义了一个公开 url 方案的应用程序并且您希望它是公开的,请不要犹豫将其发布在此站点中。

    【讨论】:

      【解决方案4】:

      试试这个:-

          NSString *phoneNumber = @"15555551212";
          NSString *dtmfAfterPickup = @"1234";
      
          NSString *telString = [NSString stringWithFormat:@"tel:%@,%@", phoneNumber, dtmfAfterPickup];
          [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telString]];
      

      【讨论】:

        【解决方案5】:

        你可以试试:

        NSURL *phoneNumberURL = [NSURL URLWithString:@"tel:80001212"];
        [[UIApplication sharedApplication] openURL:phoneNumberURL];
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-04-03
          • 1970-01-01
          相关资源
          最近更新 更多