Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swift3 - canOpenURL: failed for URL tel

Tags:

ios

swift

swift3

I want to intent a call , this is my code :

if let urlMobile = NSURL(string: "tel://076938483"), UIApplication.shared.canOpenURL(urlMobile as URL) {

                if #available(iOS 10.0, *) {
                    UIApplication.shared.open(urlMobile as URL, options: [:], completionHandler: nil)
                }
                else {
                    UIApplication.shared.openURL(urlMobile as URL)
                }
            }

I'm using swift 3 to do so but I get this error:

-canOpenURL: failed for URL: "tel://09178883828" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"

any idea to do so ?

like image 235
j jones Avatar asked Oct 16 '25 14:10

j jones


2 Answers

Your code works perfectly fine. Run it on an actual device if your using Simulator. You can't simulate a call on a Mac/MacBook.

Please have a look at Simulator Hardware Actions in Apple documentation.

like image 143
Oleh Zayats Avatar answered Oct 18 '25 04:10

Oleh Zayats


Some LSApplicationQueriesScheme do not work on Simulator. Error Code -10814 is for kLSApplicationNotFoundErr. Simulator can't launch Dial Pad for Telephone. So run it on iPhone device.

This worked for me!!!

Code Should be

if let url = NSURL(string: "tel://\(yourNumber)"), UIApplication.shared.canOpenURL(url as URL) {
  UIApplication.shared.open(url as URL, options: [:], completionHandler: nil)
}
like image 37
Manish Mahajan Avatar answered Oct 18 '25 04:10

Manish Mahajan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!