Stijn Hoste Stijn Hoste - 1 year ago 105
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!

Answer Source

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://.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download