This question already has an answer here:
- Calling a phone number in swift 18 answers
I want my app to be able to call a certain number when a button is clicked. I've tried to google it but there doesn't seem to have one for iOS 10 so far (where openURL is gone). Can someone put an example for me on how to do so? For instance like:
@IBAction func callPoliceButton(_ sender: UIButton) {
// Call the local Police department
}
By mistake my answer was misplaced, please checkout this one: You can use this:
In Swift 4.2
Call this like below
Hope this help.
used below simple lines of code, if you want to make a phone call:
// function defination:
// function call: [Used anywhere in your code]
Note: Please run the app on a real device because it won't work on the simulator.
Task
Make a call with phone number validation
Details
Xcode 9.2, Swift 4
Solution
Usage
Sample for test
Result
You can call like this:
For Swift 3+, you can use like
Make sure you've scrubbed your phone number string to remove any instances of
(
,)
,-
, orspace
.