logo
In-app Chat
SDK Error Codes
Powered Byspreading
On this page

Implement VoIP notification

Overview

The VoIP notification offers the same experience on your app as a voice call provided by an ISP carrier.

Prerequisites

Before you implement the VoIP notification feature, make sure that the following conditions are met:

  • ZPNs SDK 2.1.0 or later is integrated, and offline push notification is implemented. For more information, see Implement offline push notification.
  • Notification permission is obtained from the user.
  • Push Notifications is added to the Capabilities pane in your Xcode project.

Implementation Process

1
Apply for a VoIP service certificate

Go to developer.apple.com, and apply for a VoIP service certificate, which is a .cer file. For more information, see Create VoIP services certificates at Apple official website.

2
Export the .p12 file

Double-click the certificate file to install it on Keychain Access. In the left-side navigation pane, click login. On the Keychain Access page, click the Certificate tab, find the certificate file, and export the .p12 file.

3
Obtain resourceID

Please contact ZEGOCLOUD technical support to obtain resourceID with the iOS VoIP policy from.

4
Add Background Modes Capabilities

Open your project in Xcode. On the Signing & Capabilities tab, click Capability. In the pop-up window, double-click Background Modes.

In the configuration area of Background Modes, select Voice over IP, Background fetch, and Remote notifications.

5
Import the PushKit and CallKit libraries

Import the PushKit and CallKit libraries.

6
Import the header files before use
Untitled
#import "CallKit/CallKit.h"
#import "PushKit/PushKit.h"
1
Copied!
7
Apply for the VoIP token

Run the following code to apply for the VoIP token.

Untitled
dispatch_queue_t mainQueue = dispatch_get_main_queue();
PKPushRegistry *voipRegistry = [[PKPushRegistry alloc] initWithQueue:mainQueue];
[voipRegistry setDelegate:self]; // Replace `self` with the object to receive the VoIP notification.
NSMutableSet *desiredPushTypes = [[NSMutableSet alloc] init];
[desiredPushTypes addObject:PKPushTypeVoIP];
voipRegistry.desiredPushTypes = desiredPushTypes;
1
Copied!
8
Obtain the VoIP token

Call the didUpdatePushCredentials method to obtain the VoIP token, and then call the setVoipToken method to pass it to the ZPNs SDK.

Untitled
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials: (PKPushCredentials *)credentials forType:(NSString *)type {
    NSData *voIPToken = credentials.token;
    [[ZPNs shared] setVoipToken:voIPToken isProduct:TRUE];
}
1
Copied!
Warning

Enter the correct value of the isProduct for the development or production environment; otherwise, the ZPNs server cannot select the proper push certificate to send offline notification requests to the APNs. During packaging, if you use the development certificate, select the value for the development environment; if you use the distribution certificate, select the value for the production environment. The APNs has a better delivery rate and lower latency in a production environment than in a development environment.

9
Send and receive a VoIP notification
  • Send a VoIP notification
Note

Obtain resourceID with the VoIP policy from ZEGOCLOUD Technical Support.

In the Call invitation scenario or other scenarios that require VoIP notifications, pass in resourceID in the ZIMPushConfig method to set the push to a VoIP push.

Untitled
pushConfig.resourcesID = @"Contact ZEGOCLOUD Technical Support to obtain the value.";
1
Copied!
  • Receive a VoIP notification

If a VoIP notification is received, your app is called to trigger the didReceiveIncomingPushWithPayload method. Call the reportNewIncomingCallWithUUID method of CallKit in the callback to pull the call interface, write the logic (for more information, see CallKit), and call the completion().

Untitled
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type withCompletionHandler:(void (^)(void))completion{
    // Write the logic. For more information, visit https://developer.apple.com/documentation/callkit?language=objc.
    // Call the `reportNewIncomingCallWithUUID` method to pull the call interface of CallKit.
    completion();
}
1
Copied!

Previous

Integrate APNs

Next

Customize notification sound