简体   繁体   中英

Call number function error canOpenURL: failed for URL: “tel://0478733797” - error: “This app is not allowed to query for scheme tel”

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)

        }
    }
}

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

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..🙂

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM