简体   繁体   English

如何在 iOS 中拨打电话?

[英]How can I make phone call in iOS?

How can I make a phone call in Objective-C?如何在 Objective-C 中拨打电话?

You can initiate a call您可以拨打电话

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

So this would probably work:所以这可能会起作用:

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

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

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. telprompt让用户可以选择在电话拨号前拨打电话或取消拨打电话。 The two forward slashes after the colon are optional.冒号后面的两个正斜杠是可选的。

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、调制解调器、通过星号盒之类的东西进行连接等特定事物的数量。

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

openURL is deprecated. openURL 已弃用。

Now use this:现在使用这个:

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

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.这将是非常特定于平台的,或者您必须使用包装库来解释平台之间的差异,因此您最好 state 这是针对哪个平台。 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 可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM