iOS
Calls Voip Push Notifications

VoIP Notifications

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

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


Set up

  1. To receive push notifications in your client app, you must register your APNs certificate from Sendbird dashboard.
  2. Refer to Step 4 of the Install and Configure the Calls SDK section 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

Register

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.registerVoIPToken() method after a user’s authentication has been completed.

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

Light Color Skin
Copy
// 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 {
                return
            }
            
            // 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

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.

Light Color Skin
Copy
func removeVoIPPushToken() {
    SendBirdCall.unregisterVoIPPush(token: myVoIPPushToken) { (error) in
        guard error == nil else { return }
            // The VoIP push token has been unregistered successfully.
    }
}

UnregisterAll

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

Light Color Skin
Copy
func removeAllOfVoIPPushTokens() {
    SendBirdCall.unregisterAllVoIPPushTokens(completionHandler: ErrorHandler?) {
        guard error == nil else { return }
            // Unregistered all push tokens successfully
    }
}