如何在Objective C中打电话?

如何在Objective C中打电话?

您可以发起呼叫

https://developer.apple.com/library/content/featuredarticles/iPhoneURLScheme_Reference/PhoneLinks/PhoneLinks.html

所以这可能会奏效

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

这是从我做的一个项目中截取的:

 NSString *phoneStr = [[NSString alloc] initWithFormat:@"tel:%@",phone_number]; NSURL *phoneURL = [[NSURL alloc] initWithString:phoneStr]; [[UIApplication sharedApplication] openURL:phoneURL]; [phoneURL release]; [phoneStr release]; 

知道如何提示用户拨打一个号码也是有帮助的:

 NSURL *phoneNumber = [NSURL URLWithString:@"telprompt://13232222222"]; [[UIApplication sharedApplication] openURL:phoneNumber]; 

telprompt使用户可以select拨打电话,或者在拨打电话之前取消拨打电话。 冒号后的两个正斜杠是可选的。

以及如果你正在谈论使用Objective-C在iPhone上打电话,那么你可以做这样的事情:

 NSURL *phoneNumber = [[NSURL alloc] initWithString: @"tel:867-5309"]; [[UIApplication sharedApplication] openURL: phoneNumber]; 

如果你正在谈论在Mac上做这个事情,那么就像其他人提到的那样,如果你正在使用voip,一个调制解调器,通过类似星号的盒子等进行连接,那么它就是特定的。

删除电话号码中空的空间

 NSString *phoneNumberString = @"123 456"; phoneNumberString = [phoneNumberString stringByReplacingOccurrencesOfString:@" " withString:@""]; phoneNumberString = [NSString stringWithFormat@"tel:%@", phoneNumberString]; NSURL *phoneNumberURL = [NSURL URLWithString:phoneNumberString]]; [[UIApplication sharedApplication] openURL:phoneNumberURL]; 

openURL已被弃用。

现在使用这个:

 UIApplication *application = [UIApplication sharedApplication]; [application openURL:[NSURL URLWithString: @"tel:12125551212"] options:@{} completionHandler:nil]; 
 NSString *phoneNumber = @"Phone number here"; UIWebView *webView = [[UIWebView alloc] init]; NSURL *url = [NSURL URLWithString:numberString]; NSURLRequest *requestURL = [NSURLRequest requestWithURL:url]; webView.dataDetectorTypes = UIDataDetectorTypeNone; [webView loadRequest:requestURL]; 

这要么是非常特定于平台的,要么你将不得不使用包装库来解决平台之间的差异,所以你最好说明这个平台的目的是什么。 一般来说,大多数平台都有各种电话API可用。

在Windows系统中,例如“TAPI”,如果你的目标是ISDN等数字电话系统,情况可能会有所不同,因为还有其他的API可用。