Last active
January 31, 2022 21:40
-
-
Save alexkafer/3b1186f93846cdaab77b1f7a44e337f0 to your computer and use it in GitHub Desktop.
Simple function to prompt a phone call on iOS in Swift
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.sharedApplication().openURL(phoneURL) | |
})) | |
alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)) | |
self.presentViewController(alert, animated: true, completion: nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@lplazas just call the
UIApplication.shared.open(_:)
it will run the native phone call alert. That could work if your just want an alert with only one number.