Skip to content

Instantly share code, notes, and snippets.

@alexkafer
Last active January 31, 2022 21:40
Show Gist options
  • Save alexkafer/3b1186f93846cdaab77b1f7a44e337f0 to your computer and use it in GitHub Desktop.
Save alexkafer/3b1186f93846cdaab77b1f7a44e337f0 to your computer and use it in GitHub Desktop.
Simple function to prompt a phone call on iOS in Swift
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)
}
}
@unferna
Copy link

unferna commented Jan 31, 2022

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment