繁体   English   中英

如何在 iOS 中拨打电话?

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

如何在 Objective-C 中拨打电话?

您可以拨打电话

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

所以这可能会起作用:

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

这是从我做的一个项目中剪下来的:

NSString *phoneStr = [NSString stringWithFormat:@"tel:%@",phone_number];
NSURL *phoneURL = [NSURL URLWithString:phoneStr];
[[UIApplication sharedApplication] openURL:phoneURL];

了解如何提示用户拨打号码也可能会有所帮助:

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

telprompt让用户可以选择在电话拨号前拨打电话或取消拨打电话。 冒号后面的两个正斜杠是可选的。

好吧,如果您正在谈论使用 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];

这将是非常特定于平台的,或者您必须使用包装库来解释平台之间的差异,因此您最好 state 这是针对哪个平台。 通常,大多数平台上都有各种电话 API。

在 Windows 系统上,例如“TAPI”,如果您针对 ISDN 等数字电话系统,情况可能会有所不同,因为还有其他 API 可用。

暂无
暂无

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

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