Marco Dinatsoli Marco Dinatsoli - 2 years ago 76
iOS Question

where is the wrong in my function to make a call

this is my code to make a phone call

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

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

i am 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

Answer Source

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) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download