Calls SDKs iOS v1
Calls SDKs iOS
Calls SDKs
iOS
Version 1

VoIP notifications

Copy link

This page explains how to register, unregister, and set up VoIP push notifications for a call from your app.

Note: First, see our GitHub page to learn how to generate your certificate for iOS VoIP Services.


Set up

Copy link
  1. To receive push notifications in your app, you must register your APNs certificate from Sendbird Dashboard.
  2. Refer to the Make 1-to-1 call section on the Make first call page to enable background modes and voice over IP capabilities.
  3. Deliver incoming VoIP push notifications to the pushRegistry(_:didReceiveIncomingPushWith:for:completion:) of the push registry object.
  4. The SendBirdCall instance will only receive notifications through PushKit, so you must implement appropriate CallKit actions when the instance delivers an incoming call through its didStartRinging delegate method.

Note: With the Calls SDK, incoming calls can be received only when an app is in the foreground by using the didStartRinging delegate method. However, if both CallKit and PushKit are implemented, the Calls SDK will be able to receive incoming calls even when the app is in the background or closed.


VoIP push token registration

Copy link

Register

Copy link

To receive calls when an app is in the background or closed, a user’s device push token must be registered to the server. A device push token can be registered by using the SendBirdCall.registerVoIPPush(token:unique:completionHandler:) method after a user’s authentication has been completed.

After authenticating a user, register the VoIP push token which is acquired from the PKPushRegistryDelegate.

// Update push token
class AppDelegate: PKPushRegistryDelegate {
    func voipRegistration() {
        self.voipRegistry = PKPushRegistry(queue: DispatchQueue.main)
        self.voipRegistry?.delegate = self
        self.voipRegistry?.desiredPushTypes = [.voIP]
    }

    func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
        // User must be authenticated before registering a push token
        SendBirdCall.registerVoIPPush(token: pushCredentials.token, unique: true) { (error) in
            guard let error = error else {
                // Handle error.
            }

            // The VoIP push token has been registered successfully.
        }
    }
}

If the VoIP push token is acquired from PKPushRegistryDelegate before a user is authenticated, save the token and register it after the user authentication is completed.

Unregister

Copy link

For a user to stop receiving calls in the background or VoIP push notifications on the device, unregister their VoIP push token by using the SendBirdCall.unregisterVoIPPush(token:completionHandler:) method.

func removeVoIPPushToken() {
    SendBirdCall.unregisterVoIPPush(token: myVoIPPushToken) { (error) in
        guard error == nil else {
            // Handle error.
        }

        // The VoIP push token has been unregistered successfully.
    }
}

UnregisterAll

Copy link

Use the SendBirdCall.unregisterAllVoIPPushTokens(completionHandler:) method to unregister all VoIP push tokens of the current user.

func removeAllOfVoIPPushTokens() {
    SendBirdCall.unregisterAllVoIPPushTokens { error in
        // Unregistered all push tokens successfully.
    }
}

Note: For more guide on how to make a video app with CallKit, see this tutorial.