我找到了解决方案,需要在info.plist中添加一些代码。我是这样做的:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>tel</string>
</array>还是没有帮助。我知道这个错误:
-canOpenURL: failed:"tel://4806501708“--错误:”此应用程序不允许查询方案tel“
我打开拨号程序的代码:
NSString *phoneNumber = [@"tel://" stringByAppendingString:lblVenPhoneValue.text];
if ([UIApplication.sharedApplication canOpenURL:[NSURL URLWithString:phoneNumber]]) {
[UIApplication.sharedApplication openURL:[NSURL URLWithString:phoneNumber]];我该怎么办?
提前谢谢
发布于 2016-03-04 10:54:30
你在设备上测试这个吗?,因为这在模拟器上不起作用。设备也应该有sim卡。
确认以上内容后,尝试如下
在info.plist中
<key>LSApplicationQueriesSchemes</key>
<array>
<string>tel</string>
<string>telprompt</string>
</array>哪里要开电话拨号机?
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",@"digits"]]]; 或
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt:%@",@"digits"]]];发布于 2016-03-04 10:15:13
只要把"//“从”tel://“中删除就可以了
NSString *phoneNumber = [@"tel:" stringByAppendingString:lblVenPhoneValue.text];
if ([UIApplication.sharedApplication canOpenURL:[NSURL URLWithString:phoneNumber]]) {
[UIApplication.sharedApplication openURL:[NSURL URLWithString:phoneNumber]];为了获得更好的检查,您可以使用
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:[NSString stringWithFormat:phoneNumber]]])
{
CTTelephonyNetworkInfo *networkInfo = [CTTelephonyNetworkInfo new];
CTCarrier *carrier = [networkInfo subscriberCellularProvider];
NSString *_code = [carrier mobileNetworkCode];
if(_code)
{
[[UIApplication sharedApplication] openURL:phoneNumber]];
}
else
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"no_sim" message:@"" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert show];
}
}
else
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"alert" message:@"alert_device_not_support" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert show];
}发布于 2018-09-26 07:19:25
对于SWIFT4.0,请使用此方法(确保您不在模拟器上)
let cleanPhoneNumber = phone.components(separatedBy: CharacterSet.decimalDigits.inverted).joined(separator: "")
let urlString:String = "tel://\(cleanPhoneNumber)"
if let phoneCallURL = URL(string: urlString) {
if (UIApplication.shared.canOpenURL(phoneCallURL)) {
UIApplication.shared.open(phoneCallURL, options: [:], completionHandler: nil)
}
}https://stackoverflow.com/questions/35792681
复制相似问题