我正在尝试使用以下方法从 iOS 应用程序调用电话号码:
它不起作用,尽管调用了该方法:
-(IBAction)callPhone:(id)sender {
NSString *phoneCallNum = [NSString stringWithFormat:@"tel://%@",listingPhoneNumber ];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneCallNum]];
NSLog(@"phone btn touch %@", phoneCallNum);
}
NSLog
输出:phone btn touch tel://+39 0668806972
您的代码是正确的。您是否 checkin 了真实设备。此功能在模拟器中不起作用。
也试试这个,
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 版本**
if let url = URL(string: "telprompt:\(phoneNumber)") {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(call, options: []) { result in
// do something with result
}
}
}