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!'
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://.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With