Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dial number from iOS app: Cannot convert the expression's type 'Bool' to type 'NSURL!'

Tags:

ios

swift

iphone

I want to make a call button in an iOS app which 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!'

like image 247
Stijn Hoste Avatar asked Jul 29 '14 17:07

Stijn Hoste


1 Answers

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!)

Example

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

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

like image 161
Rafa de King Avatar answered Oct 05 '22 13:10

Rafa de King