2

this is my code to make a phone call

let phoneCall = phoneNumberTF.text
        if let phoneCall = phoneCall {
            let url = NSURL(string: "tel://\(phoneCall)")
            UIApplication.sharedApplication().openURL(url!)

        }else {
            let alert = UIAlertController(title: "Error", message: "not correct phone", preferredStyle: .Alert)
            let action = UIAlertAction(title: "Retry", style: .Default, handler: nil)
            alert.addAction(action)
        }

I'm getting this error in the log

ERROR: There is no registered handler for URL scheme tel

hint: I already check this question, but the solution didn't work with me Calling a phone number in swift

Community
  • 1
  • 1
Marco Dinatsoli
  • 10,322
  • 37
  • 139
  • 253

2 Answers2

2

the correct url scheme is something like tel:PHONE_NUMBER (without the slashes you included). you should also check if the application CAN open the url you provide by calling UIApplication.sharedApplication.canOpenURL()...

let phoneNumber = "123-456-789"
let phoneURL = NSURL(string: "tel:\(phoneNumber)")!
if UIApplication.sharedApplication().canOpenURL(phoneURL) {
  UIApplication.sharedApplication().openURL(phoneURL)
}
André Slotta
  • 13,774
  • 2
  • 22
  • 34
  • sure: https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/PhoneLinks/PhoneLinks.html#//apple_ref/doc/uid/TP40007899-CH6-SW1 – André Slotta Nov 05 '15 at 22:04
1

Per Apple docs https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/PhoneLinks/PhoneLinks.html

The correct format is tel:. So first change that and then you should check if the UIApplication.sharedApplication.canOpenURL() before doing it. If you're running on a simulator it will not work.

Peter Foti
  • 5,526
  • 6
  • 34
  • 47