0

I am getting this error in the log?

Though I am running this on the simulator, will this matter in the testing stage?

canOpenURL: failed for URL: "tel://0478733797" - error: "This app is not allowed to query for scheme tel" callNumber button pressed

Here is my function.

The string is "0478733797"

func callNumber(phoneNumber:String) {
    if let phoneCallURL = URL(string: "tel://\(phoneNumber)") {
        let application:UIApplication = UIApplication.shared
        if (application.canOpenURL(phoneCallURL)) {
            application.open(phoneCallURL, options: [:], completionHandler: nil)

        }
    }
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579

2 Answers2

0

The error you are facing describes that you have not allowed your app to open an query scheme. To solve that you should add following permission in your info.plist

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

And run your application on the Device instead of Simulator

Nikunj Damani
  • 753
  • 3
  • 11
0

To make a call to a number, you simply need to do this:

let urlSchema = "tel:"
let numberToCall = "0478733797"
if let numberToCallURL = URL(string: "\(urlSchema)\(numberToCall)")
{
    if UIApplication.shared.canOpenURL(numberToCallURL)
    {
        UIApplication.shared.openURL(numberToCallURL)
    }
}

Only the URL that you are creating using tel: is not in the correct format.

There is no need to add anything to the Info.plist. Also, call is not supported on an iOS Simulator. So try running it on an actual device.

Let me know if you still face any issues. Happy Coding..

PGDev
  • 23,751
  • 6
  • 34
  • 88