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

Customize notification click redirection


Note
This document applies only to Apple Push Notification service (APNs).

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:

How to implement

1
Enable the Feature

Please contact ZEGOCLOUD technical support to configure and enable the feature of notification click redirection.

2
Listen to the Callback

Before calling the registerPush method, listen to the onNotificationClicked method in ZPNsEventHandler, in order to obtain the path of the target page to jump to.

Untitled
ZPNsEventHandler.onNotificationClicked = (ZPNsMessage message){
    if(zpnsMessage.pushSourceType == ZPNsPushSourceType.FCM){
        // FCM does not support this interface, please use Intent in Android Activity to obtain the payload.
    }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-flutter/offline-push-notifications/implement-offline-push-notification#implement-the-offline-push-notification-using-the-zim-sdk).
        String payload = message.payload; 
        // You can write code to implement navigation based on the above information
    }
};
1
Copied!
3
Configure the Pass-Through Field

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.

4
Trigger the Callback

After receiving the push notification, when the receiver clicks on it, ZPNs will trigger the onNotificationClicked 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.

Previous

Customize notification sound

Next

ResourcesID introduction