从iPhone应用程序拨打电话

可能重复:
从我的应用程序中拨打电话

我想打电话给我的iPhone应用程序给定的号码。 你能提出一个很好的解释它的最好的教程,或者告诉我这个过程吗?

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

你可以试试 :

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

尝试这个:-

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

通过“url scheme”机制在iOS中pipe理另一个应用程序中的应用程序。 如果一个应用定义了一个urlscheme,并且这个scheme是公开的,那么你可以使用它来运行该应用。 基本的规则是首先检查你的设备是否支持该scheme(例如你不能在iPad上拨打电话,因为没有安装电话应用程序),然后如果答案是肯定的,请将其称为:

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

这个检查对于一些scheme是重要的,例如电话号码,系统检查是否URL正确。 例如:对于电话号码,数字之间的空格不被支持。

最常见的Apple URLscheme在这里描述: http : //developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/PhoneLinks.html#//apple_ref/doc/uid/TP40007893-SW1特别是,电话urlscheme在这里: http : //developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/PhoneLinks.html#//apple_ref/doc/uid/TP40007893-SW1

最后有一个名为handleOpenURL的网站,试图收集所有的应用程序urlscheme。 如果您定义的应用程序公开了一个urlscheme,并且希望它公开,请不要犹豫,将其发布到本网站。

有两种方法可以达到这个效果:

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

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

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

如果你想显示自定义tableview单元格内的电话号码有帮助。

由于某些项目的要求,我个人喜欢第二个。 当我给UITextView的电话号码,并按下后,将开始呼叫。