iOS
Calls Voip Push Notifications

VoIP Push Notifications

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


Setup

  1. To receive push notifications in your app, you must register your APNs certificate from your dashboard.
  2. Refer to Step 4 from 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 providing it as a parameter in the authenticate() method when authenticating a user, or by using the SendBirdCall.registerVoIPToken() method after a user’s authentication has been completed.

When authenticating, register a VoIP push token for a client app to receive notifications from APNs as shown below:

Light Color Skin
Copy
let params = AuthenticateParams(userId: USER_ID, voipPushToken:PUSH_TOKEN)
SendBirdCall.authenticate(with: params) { (user, error) in
    //
}

Or, prior 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) {
        SendBirdCall.register(pushToken: pushCredentials.token, unique: true) { (error) in
            guard let error = error else {
                return
            }
            
            // The VoIP push token has been registered successfully.
        }
    }
}

If a user is not authenticated but the VoIP push token acquired from PKPushRegistryDelegate is registered, an error is returned for actions such as accepting a call. When the user tries to authenticate later, they can authenticate with the VoIP push token saved in the Calls SDK.

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.unregister(pushToken:completionHandler:) method.

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

UnregisterAll

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

Light Color Skin
Copy
func removeAllOfVoIPPushTokens() {
SendBirdCall.unregisterAllPushTokens(completionHandler: ErrorHandler?) {
    guard error == nil else { return }
        // All VoIP push tokens have been unregistered successfully.
    }
}