我使用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);
})
因此,如果用户单击推送通知,则应该打开Web浏览器并重定向到代码中我附加的页面
答案 0 :(得分: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);
}
}
答案 1 :(得分:0)
"message":{
"token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification":{
"title":"Portugal vs. Denmark",
"body":"great match!"
},
"data" : {
"Nick" : "Mario",
"Room" : "PortugalVSDenmark"
}
}
通知有效载荷必须是这样的。
https://firebase.google.com/docs/cloud-messaging/concept-options