如何在 iOS 中拨打电话?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/665769/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I make phone call in iOS?
提问by Bala
How can I make a phone call in Objective-C?
如何在 Objective-C 中拨打电话?
回答by Lou Franco
You can initiate a call
您可以发起呼叫
So this would probably work:
所以这可能会起作用:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:12125551212"]];
回答by GoatRider
This is clipped from a project I did to do just that:
这是从我做的一个项目中剪辑出来的:
NSString *phoneStr = [NSString stringWithFormat:@"tel:%@",phone_number];
NSURL *phoneURL = [NSURL URLWithString:phoneStr];
[[UIApplication sharedApplication] openURL:phoneURL];
回答by Mieczys?aw Daniel Dyba
It may also be helpful to know how to prompt the user to call a number:
了解如何提示用户拨打号码也可能会有所帮助:
NSURL *phoneNumber = [NSURL URLWithString:@"telprompt://13232222222"];
[[UIApplication sharedApplication] openURL:phoneNumber];
telprompt
gives the user a choice to place the call or cancel making the call before the phone dials. The two forward slashes after the colon are optional.
telprompt
使用户可以在电话拨号前选择拨打电话或取消拨打电话。冒号后的两个正斜杠是可选的。
回答by nstehr
well if you are talking about using objective-c to make a phone call on the iphone, then you can do something like this:
好吧,如果您正在谈论使用 Objective-c 在 iphone 上拨打电话,那么您可以执行以下操作:
NSURL *phoneNumber = [[NSURL alloc] initWithString: @"tel:867-5309"];
[[UIApplication sharedApplication] openURL: phoneNumber];
If you are talking about doing this on a mac ,well, then like others have mentioned that is specific based on number of things like, if you are using voip, a modem, connecting through something like an Asterisks box, etc..
如果您正在谈论在 mac 上执行此操作,那么就像其他人提到的那样,这取决于许多事情,例如,如果您使用的是 voip、调制解调器、通过诸如星号盒之类的东西进行连接等。
回答by Mazen Kasser
REMOVE EMPTY SPACES IN PHONE NUMBER
删除电话号码中的空白空间
NSString *phoneNumberString = @"123 456";
phoneNumberString = [phoneNumberString stringByReplacingOccurrencesOfString:@" " withString:@""];
phoneNumberString = [NSString stringWithFormat@"tel:%@", phoneNumberString];
NSURL *phoneNumberURL = [NSURL URLWithString:phoneNumberString]];
[[UIApplication sharedApplication] openURL:phoneNumberURL];
回答by Alessandro Pirovano
openURL is deprecated.
openURL 已弃用。
Now use this:
现在使用这个:
UIApplication *application = [UIApplication sharedApplication];
[application openURL:[NSURL URLWithString: @"tel:12125551212"] options:@{} completionHandler:nil];
回答by MaxEcho
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];
回答by none
This will either be very platform-specific, or you'll have to use a wrapper library to account for the differences among platforms, so you better state what platform this is intended for. In general, there are various telephony APIs available on most platforms.
这要么是非常特定于平台的,要么您必须使用包装库来说明平台之间的差异,因此您最好说明这是针对哪个平台的。通常,大多数平台上都有各种电话 API。
On Windows systems there's for example the "TAPI", also things may somewhat differ if you are targeting a digital telephone system such as ISDN, because there are other APIs available.
例如,在 Windows 系统上有“TAPI”,如果您的目标是 ISDN 等数字电话系统,情况可能会有所不同,因为还有其他可用的 API。