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

Implement silent push notifications

Introduction

Silent push notifications are a special type of remote notification, mainly used for data synchronization between the App running in the background and the server. For example: when the App is not active and the data within the App is outdated, the server will send a silent push notification, and the App will update the data without any user awareness.

Warning
  • Silent push notifications are primarily used for updating and synchronizing data, without any user awareness. Therefore, silent push notifications generally do not have content, sounds, or badge notifications.
  • When silent push notifications awaken the background App for download tasks, there is a maximum of 30 seconds to perform.
  • Notifications callbacks can be triggered when the App is running in the foreground/background, or when the background process is suspended (retaining the App's memory resources). Callbacks cannot be triggered after the App is closed.
  • Silent push requests are low priority tasks at APNs, and Apple does not guarantee the delivery rate of silent pushes.
  • Do not use silent push notifications to keep the App alive. If APNs detect a high frequency of silent push requests, it may terminate their transmission.
Note

This documentation is applicable to the following platforms: iOS and Android (only smart devices that support Google services).

Prerequisites

Before implementing silent push notifications, please make sure of the following:

Implementation steps

Send silent push notifications

  1. Contact ZEGOCLOUD technical support to configure the resourceID for carrying silent push strategies. There are two types of silent push strategies: iOS and FCM. Depending on your specific requirements, you can choose to only carry one type of silent push strategy's resourceID.

  2. In scenarios where offline push notifications need to be sent (such as call invitation, offline push notification, etc.), fill in the resourceID field of ZIMPushConfig with the pre-configured value obtained from ZEGOCLOUD technical support. Additionally, fill in the payload field according to the specific business scenario.

Untitled
var pushConfig = {
    resourcesID: "your resourcesID", // resourcesID configured by ZEGOCLOUD technical
    title: "your title",
    content: "your content",
    payload: "your payload",
};
1
Copied!
  1. Once the above steps are completed, you can send silent push notifications to others.

Receive silent push notifications

When an iOS or Android app is in the foreground, or in the background but not terminated

To receive online silent push notifications, register the throughMessageReceived event.

Untitled
ZPNs.getInstance().on('throughMessageReceived', message => {
    console.log('ZPNs throughMessageReceived', message);
    // Handle online silent push notifications
})
1
Copied!

When Android App is terminated in the Background

You need to import ZPNs in the entry file of your project and call setBackgroundMessageHandler to set a callback for receiving offline silent push notifications.

Untitled
import ZPNs from 'zego-zpns-react-native';

/** Code in the entry file of your project, no need for you to modify **/
// import { AppRegistry, Platform } from 'react-native';
// import App from './App';
// import { name as appName } from './app.json';

// AppRegistry.registerComponent(appName, () => App);
/** Code in the entry file of your project, no need for you to modify **/

// Note: The following code should not be called in UI components!
ZPNs.setBackgroundMessageHandler(message => {
    console.log('ZPNs backgroundMessageHandler', message);
    // Handle offline silent push notifications on Android
})
1
Copied!

By completing the above steps, you will be able to receive silent push notifications from others.

Previous

Cross application offline push

Next

Custom notification icon