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
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.
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.
Please contact ZEGOCLOUD technical support to obtain resourceID with the iOS VoIP policy from.
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.
Import the PushKit and CallKit libraries.
Call the applyNotificationPermission method to request the user's consent for the app's notification permission.
ZPNs.getInstance().applyNotificationPermission();
Before using VoIP, you need to call registerPush, set the current iOS environment, and set enableIOSVoIP
to true.
ZPNs.getInstance()
.registerPush(iOSEnvironment: ZPNsIOSEnvironment.Development,enableIOSVoIP: true)
.catchError((onError) {
if (onError is PlatformException) {
// You need to pay attention to the exceptions that may be thrown here
log(onError.message ?? "");
}
});
Please enter the correct value of the iOSEnvironment
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.
Get the pushID with VoIP token through the onRegistered method.
ZPNsEventHandler.onRegistered = (ZPNsRegisterMessage registerMessage) {
log(registerMessage.errorCode.toString());
};
- Send a VoIP notification
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.
pushConfig.title = "System call title";
pushConfig.payload = "Transmitted fields required by the business";
pushConfig.resourcesID = "Contact ZEGOCLOUD Technical Support to configure resourcesID";
ZIMVoIPConfig voIPConfig = ZIMVoIPConfig();
voIPConfig.iOSVoIPHandleType = ZIMCXHandleType.generic;
//Contact information of the sender
voIPConfig.iOSVoIPHandleValue = "Li hua";
//Is it a video call
voIPConfig.iOSVoIPHasVideo = false;
pushConfig.voIPConfig = voIPConfig;
- Receive a VoIP notification
To facilitate Flutter developers to use iOS native Callkit library interfaces, ZEGOCLOUD encapsulates the relevant interfaces into the zego_callkit plugin. Please refer to CallKit.