how to open phone dialler in iOS 9?

Viewed 12942

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

4 Answers

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

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