Home
/
Calls
/
iOS

Make your first call

The Calls SDK adds call features to your client app with a few simple steps. To make your first call, do the following steps:


Step 1: Initialize the Calls SDK in your app

First, the SendBirdCall instance must be initialized when a client app is launched. Initialization is done by using the APP_ID of your Sendbird application in the dashboard. If the instance is initialized with a different APP_ID, all existing call-related data in a client app will be cleared and the SendBirdCall instance will be initialized again with the new APP_ID.

Light Color Skin
Copy
// Initialize SendBirdCall instance to use APIs in your app.
SendBirdCall.configure(appId: APP_ID)

Step 2: Authenticate a user and add a registration token

To make and receive calls, authenticate a user to Sendbird server by using their user ID through the authenticate() method. To receive calls while an app is in the background or closed, a user’s device token must be added to the server. A device token can be added by passing it as an argument to a parameter in the authenticate() method when authenticating a user, or by using the SendBirdCall.registerVoIPPush() method after a user’s authentication has been completed.

Note: Go to the VoIP push notifications page to learn more about registering push tokens.

Light Color Skin
Copy
// The USER_ID below should be unique to your Sendbird application.
let params = AuthenticateParams(userId: USER_ID, accessToken: ACCESS_TOKEN)
SendBirdCall.authenticate(with: params) { (user, error) in
    guard let user = user, error == nil else {
        // Handle error.
    }

    // The user has been authenticated successfully and is connected to Sendbird server.
    ...
}

Note: You can implement both the Chat and Calls SDKs to your client app. Two SDKs can work on the same Sendbird application for them to share users. In this case, you can allow Calls to retrieve a list of users in the client app by using the Chat SDK’s method or Chat API.


Step 3: Add event delegates

There are two types of event handlers that the Calls SDK provides: SendBirdCallDelegate and DirectCallDelegate.

SendBirdCallDelegate

Add a device-specific SendBirdCallDelegate event delegate using the SendBirdCall.addDelegate(:) method. Once the event delegate is added, responding to device events such as incoming calls can be managed as shown below:

Light Color Skin
Copy
SendBirdCall.addDelegate(self, identifier: UNIQUE_HANDLER_ID)

class MyClass: SendBirdCallDelegate {
    func didStartRinging(_ call: DirectCall) {
        // Process an incoming call.
        // IMPORTANT: - Refer to the Make a call and Receive a call sections below for what to do here.
        ...
    }
}

DirectCallDelegate

Add a call-specific DirectCallDelegate event delegate using call.delegate. Responding to call-specific events such as call connected is then managed as shown below:

Light Color Skin
Copy
func didEstablish(_ call: DirectCall)
func didConnect(_ call: DirectCall)
func didRemoteAudioSettingsChange(_ call: DirectCall)
func didEnd(_ call: DirectCall)
... // more call-specific delegate methods.

// Refer to the API reference for more delegate methods

Step 4: Make a call

Initiate a call by passing the callee’s user ID as an argument to a parameter in the SendBirdCall.dial() method. Use the CallOptions object to choose initial call configuration, such as audio or video capabilities, video settings, and mute settings.

Light Color Skin
Copy
let params = DialParams(calleeId: CALLEE_ID, callOptions: CallOptions())

SendBirdCall.dial(with: params) { (directCall, error) in
    guard let directCall = directCall, error == nil else {
        // Handle error.
    }

    // The call was successfully made.
    directCall.delegate = self
    ...
}

Step 5: Receive a call

To receive an incoming call, a SendBirdCallDelegate event delegate should already be registered in the callee’s client app. Accept or decline the call using the directCall.accept() or the directCall.end() method. If the call is accepted, a media session will automatically be established by the Calls SDK.

Before accepting the call, the call-specific DirectCallDelegate event delegate must be added to the call object. It enables the callee’s app to react to events happening during the call through its callback methods.

Light Color Skin
Copy
SendBirdCall.addDelegate(self, identifier: UNIQUE_HANDLER_ID)
Class MyClass: SendBirdCallDelegate, DirectCallDelegate {
    func didStartRinging(_ call: DirectCall) {
        call.accept()
        call.delegate = self
    }
}

The callee’s client app receives an incoming call through either the established connection with Sendbird server or a VoIP Push Notifications when the app is in the background. To use the Calls SDK in the callee’s client app, the SendBirdCall instance must deliver received VoIP push notifications to the Calls SDK.

Light Color Skin
Copy
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) {
    SendBirdCall.pushRegistry(registry, didReceiveIncomingPushWith: payload, for: type, completionHandler:{ callUUID in
        ...
    })
}