如何从ios应用程序拨打电话号码? [英] How to call a phone number from ios app?
本文介绍了如何从ios应用程序拨打电话号码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正试图通过以下方式拨打ios应用程序中的电话号码:
虽然方法被调用,但它无法正常工作:
I'm trying to call a phone number from ios app using: It's not working, although the method gets called:
-(IBAction)callPhone:(id)sender {
NSString *phoneCallNum = [NSString stringWithFormat:@"tel://%@",listingPhoneNumber ];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneCallNum]];
NSLog(@"phone btn touch %@", phoneCallNum);
}
NSLog
输出:手机btn touch tel:// + 39 0668806972
NSLog
output: phone btn touch tel://+39 0668806972
推荐答案
你的代码是正确的。你检查了真实的设备吗?此功能在模拟器中不起作用。
your code is correct. did you check in real device. this function will not work in simulator.
试试这个,
NSString *phNo = @"+919876543210";
NSURL *phoneUrl = [NSURL URLWithString:[NSString stringWithFormat:@"telprompt:%@",phNo]];
if ([[UIApplication sharedApplication] canOpenURL:phoneUrl]) {
[[UIApplication sharedApplication] openURL:phoneUrl];
} else
{
calert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Call facility is not available!!!" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[calert show];
}
** Swift 3版本**
** Swift 3 version**
if let url = URL(string: "telprompt:\(phoneNumber)") {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.openURL(url)
}
}
这篇关于如何从ios应用程序拨打电话号码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文