How to make a phone call in the iOS app

In iOS applications, we can make phone calls programmatically using the application. In this tutorial, we will see how we can make a phone call in an iOS app.

Consider the following steps to make the phone call in the iOS app.

Step 1: Project creation

To create a new project in XCode, open XCode and navigate to New Project -> Single View Application as shown in the below image.

How to make a phone call in the iOS app

Provide the following details and click Next to create the iOS project in XCode.

How to make a phone call in the iOS app

This will create our iOS application named as CallApp.

Step 2: Configure User Interface in the storyboard

now open the Main.storyboard and add a text field to get input from the user and a button to trigger the submit event in the app, as shown below image.

How to make a phone call in the iOS app

Step 3 - Configure View Controller Code

In ViewController.swift, create the outlet for the text field and the action outlet for submit button. Once we add the outlets, the ViewController code will look like below.

Step 4: Configure clickedMakeCall()

To make a call, we can use the open(_ url:URL) method of UIApplication. We need to add the code to make the call in the clickedMakeCall() method. Add the following code in the method.

Step 5 - Now, run the application and enter the mobile number we need to call from the app.

How to make a phone call in the iOS app

Step 6 - Click the Make Call button, we will be shown an alert with 'Call' and 'Cancel' options.

How to make a phone call in the iOS app

Step 8 - Click on the call button, the call will be made to the number, as shown below.

How to make a phone call in the iOS app




Latest Courses