Stijn Hoste Stijn Hoste - 3 months ago 60
Swift Question

Dial number from iOS app

I want to make a call button in an iOS app wich prompts the native call pop-up with a number I supply.

This is the code I have at this moment:

@IBAction func btnCall(sender : AnyObject) {
UIApplication .sharedApplication() .openURL(url: "tel://0000000000")

This is the error I'm getting:

Cannot convert the expression's type 'Bool' to type 'NSURL!'

Any help or hints are really appreciated!


The openURL method is expecting a NSURL object and you are passing a string there. That's why it is not working.

Use the NSURL class method:

class func URLWithString(_ URLString: String!)


UIApplication.sharedApplication().openURL(url: NSURL(string:"tel:0000000000"))

Notice that also the URL schema is tel: and not tel://.