Customize notification click redirection
Introduction
Usually, when users click on an offline push notification, they are directed to the home page of the app. With this feature, developers can customize the click direction logic of offline push notifications. For example, when users click on a push message, they can be redirected to a specified page, thereby enhancing user experience and interaction efficiency.
Prerequisites
Before customizing notification click redirection, please ensure that:
- You have integrated ZPNs SDK version 2.8.0 or higher. For more details, refer to Implement offline push notification.
- You have upload the APN's certificates in the ZEGOCLOUD console. For more details, refer to Integrate APNs.
How to implement
Please contact ZEGOCLOUD technical support to configure and enable the feature of notification click redirection.
Before calling the registerPush method, listen to the notificationClicked method in ZPNsEventHandler, in order to obtain the path of the target page to jump to.
ZPNs.getInstance().on('notificationClicked', message => {
if (message.pushSourceType == ZPNsPushSourceType.FCM){
// FCM does not support this interface, please use Intent to get the payload in the Android Activity.
}else{
// Obtain the payload(i.e., the path of the target page to jump to)
// Same as the "ZIMPushConfig > payload passed when sending messages. Please refer to [Implement offline push notification - Implement the offline push notification using the ZIM SDK](https://www.zegocloud.com/docs/zim-rn/offline-push-notifications/implement-offline-push-notification#implement-the-offline-push-notification-using-the-zim-sdk).
const payload = message.payload;
// You can write code to implement the jump based on the above information
}
});
The message sender needs to set the pass-through field via the ZIMPushConfig > payload
parameter when sending messages (for example, the path of the target page that needs to be navigated to). For related code, please refer to Implement offline push notification - Implement the offline push notification feature with the ZIM SDK.
After receiving the push notification, when the receiver clicks on it, ZPNs will trigger the notificationClicked event.
If you have not called ZPNs' registerPush method at the time of clicking, this event will be cached until you call the registerPush method, after which it will be triggered.