Updated 1 July 2021
Hello guys, Today we will learn about the Dialer with a phone number functionality.
In this blog, we are going to learn about how to implement the Dialer with a phone number method.
Nowadays, you have seen several apps which are open a dialer with a specific number, and also we can make direct calls to them. This functionality is very useful and easy to implement.
For the dialer code, you need to add some program that is used to call the dialer method in your phone –
1 2 3 |
if let url = URL(string: "tel://\(phoneTextField.text!)"), UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url, options: [:], completionHandler: nil) |
Firstly create an XCode project and make a screen, in it we take a textField and a call button
Now create a viewController.swift file and add the dialer code to it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import UIKit class ViewController: UIViewController { @IBOutlet weak var phoneTextField: UITextField! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } @IBAction func callButtonTap(_ sender: Any) { if let url = URL(string: "tel://\(phoneTextField.text!)"), UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url, options: [:], completionHandler: nil) } } } |
Now run the code on a real device call method is not work on the simulator
After running the code we got the result-
Conclusion:-
In this blog, we have discussed how to call dialer function
I hope this blog will help you in getting about dialer functionality
Thanks for reading!
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.