How to Make a Phone Call from an iOS App (Swift)

In this article, we will explain how to make a phone call from an iOS app using Swift.

This time, we'll create a simple app where tapping a button labeled Call Test will dial a specified phone number.

How to Make a Phone Call from an iOS App 1

Prepare the iOS App to Make a Phone Call

First, let's create a simple iOS app for testing that makes a phone call when the button is tapped.

Create a new project in Xcode using [iOS] → [App].

For the design, you can place the elements anywhere. In Main.storyboard, add a Button to the View Controller.

How to Make a Phone Call from an iOS App 2


Create a TouchUpInside action from the button named callTestTapped.

How to Make a Phone Call from an iOS App 3

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    @IBAction func callTestTapped(_ sender: Any) {
    }
}

How to Make a Phone Call from an iOS App with Swift

Now, let's write the Swift code to make a phone call from the iOS app.

Modify the callTestTapped() method in ViewController.swift as follows:

@IBAction func callTestTapped(_ sender: Any) {
    let phoneNumber = "+81351598200"
    guard let url = URL(string: "tel://" + phoneNumber) else { return }
    UIApplication.shared.open(url)
}

On line 2, the app will dial the phone number defined in phoneNumber. Hyphens in the number, such as +81-3-5159-8200, are also acceptable.

On line 3, a URL is created using tel://. If the URL initialization fails, the guard let statement returns early.

On line 4, the generated URL is passed to UIApplication.shared.open(), which launches the app that handles phone calls.

This assumes that the device where the app is installed has an app capable of handling tel:// URLs.


That's all the code needed in Swift to make a phone call from an iOS app.

No additional permission settings in info.plist are required.


Test the iOS App on an iPhone

You cannot test the phone call feature in the simulator. Instead, you'll need to install and run the app on a physical iPhone that can make calls.

When you run the app on your iPhone, you'll see a screen like this:

How to Make a Phone Call from an iOS App 4


When you tap the Call Test button, a confirmation dialog will appear asking if you want to place the call.

How to Make a Phone Call from an iOS App 5


If you tap Call +81 3 5159 8200, the call will be placed.

How to Make a Phone Call from an iOS App 6


That's how you can make a phone call from an iOS app using Swift.