7

I found solution that I need to add some code in info.plist. I did it like below:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>tel</string>
</array>

still no help. I get this error:

"-canOpenURL: failed for URL: "tel://4806501708" - error: "This app is not allowed to query for scheme tel"

my code for opening dialler:

NSString *phoneNumber = [@"tel://" stringByAppendingString:lblVenPhoneValue.text];
if ([UIApplication.sharedApplication canOpenURL:[NSURL URLWithString:phoneNumber]]) {
        [UIApplication.sharedApplication openURL:[NSURL URLWithString:phoneNumber]];

What do I need to do?
Thanks in Advance

9
  • [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",@"digits"]]]; try this , without "//" Commented Mar 4, 2016 at 10:10
  • NSString *phoneNumber = [@"telprompt://" stringByAppendingString:@number]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]]; check this too if above not work Commented Mar 4, 2016 at 10:11
  • no luck. still getting : "This app is not allowed to query for scheme telprompt" Commented Mar 4, 2016 at 10:27
  • is my info.plist correct? here it is Commented Mar 4, 2016 at 10:27
  • telprompt try this in info.plist Commented Mar 4, 2016 at 10:28

4 Answers 4

14

Are you testing this on device ? , because this will not work on simulator . And device should have sim card too .

After confirming above try following

In info.plist

<key>LSApplicationQueriesSchemes</key>
<array>
<string>tel</string>
<string>telprompt</string>
</array>

Where want to open phone dialler

 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",@"digits"]]]; 

or

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt:%@",@"digits"]]];
1
  • 2
    without adding LSApplicationQueriesSchemes also it works fine Commented Feb 28, 2017 at 11:28
1

just remove "//" from @"tel://" it should work

NSString *phoneNumber = [@"tel:" stringByAppendingString:lblVenPhoneValue.text];
if ([UIApplication.sharedApplication canOpenURL:[NSURL URLWithString:phoneNumber]]) {
        [UIApplication.sharedApplication openURL:[NSURL URLWithString:phoneNumber]];

For more better checks you can use

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];
}
2
  • I forgot to mention that i use simulator. Maybe thats the reason of failure. I should check on device. Commented Mar 4, 2016 at 10:39
  • ohh. That should be the reason, then you should add check/alert for such conditions
    – aman.sood
    Commented Mar 4, 2016 at 11:48
0

for Swift 4.0 use this(Make sure you are not on the simulator)

        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)
            }
        }
0

This will not work in the simulator, but it works fine in iPhone device.

private func makeCall(number:String){ let number = "9876543210"

    if let url = URL(string: "tel://\(number)"), UIApplication.shared.canOpenURL(url) {
        if #available(iOS 10, *) {
            UIApplication.shared.open(url)
        } else {
            UIApplication.shared.openURL(url)
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.