发送带有外部链接的推送通知(React Native)

问题描述 投票:0回答:1

我使用react-native-firebase构建了一个简单的react-native应用。我成功发送了一个推送通知到我的设备,然后我想实现如果用户从设备触摸(单击)该通知,它将重定向到我附加到的网页。

我安装了fcm-node发送推送通知。代码如下

const FCM = require('fcm-node');

const message = {
    notification: {
        fcmTitle,
        body
    },
    to: token
};


 fcm.send(message, function (err, response) {
    console.log('response',response);
    console.log("error : "+err);
 })

因此,如果用户单击推送通知,则应打开网络浏览器并从代码重定向到我附加的页面

firebase react-native push-notification react-native-firebase react-native-fcm
1个回答
0
投票

这由Firebase SDK处理。在这里,当用户点击通知时,您的应用会收到与该通知关联的有效负载。

请看一下如何处理

async createNotificationListeners() {
/*
 Triggered when a particular notification has been received in foreground
*/
this.notificationListener = 
 firebase.notifications().onNotification((notification) => {
   const { title, body } = notification;
  this.showAlert(title, body);
});

/*
 If your app is in background, you can listen for when a notification is clicked / tapped / opened as follows:
 */
 this.notificationOpenedListener = 
firebase.notifications().onNotificationOpened((notificationOpen) => {
   const { title, body } = notificationOpen.notification;
    this.showAlert(title, body);
 });

 /*
 If your app is closed, you can check if it was opened by a notification being clicked / tapped / opened as follows:
 */
const notificationOpen = await 
firebase.notifications().getInitialNotification();
 if (notificationOpen) {
   const { title, body } = notificationOpen.notification;
   this.showAlert(title, body);
}

}
© www.soinside.com 2019 - 2024. All rights reserved.