Instantly share code, notes, and snippets.
chitu98
/ makeCallButtonAction.swift
Created
August 25, 2019 06:33
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// call function via button | |
@IBAction func btnCall(_ sender: UIButton) { | |
makePhoneCall(phoneNumber: "9981787829") | |
} | |
chitu98
/ makeCallButtonFunction.swift
Created
August 25, 2019 06:32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |