Skip to content

Instantly share code, notes, and snippets.

// call function via button
@IBAction func btnCall(_ sender: UIButton) {
makePhoneCall(phoneNumber: "9981787829")
}
func makePhoneCall(phoneNumber: String) {
if let phoneURL = NSURL(string: ("tel://" + phoneNumber)) {
let alert = UIAlertController(title: ("Call " + phoneNumber + "?"), message: nil, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Call", style: .default, handler: { (action) in
UIApplication.shared.open(phoneURL as URL, options: [:], completionHandler: nil)
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))