【发布时间】:2018-12-09 17:42:29
【问题描述】:
我正在使用 react-native-firebase 实现推送通知。所以,我正在测试云消息传递。当屏幕关闭并处于后台时,我可以收到通知。但是,当应用程序运行时,我无法收到通知。我的代码有什么问题还是我需要添加一些代码?
async createNotificationListeners() {
this.notificationListener = firebase.notifications.onNotification((notification) => {
const { title, body } = notification;
this.showAlert(title, body);
});
this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen) => {
const { title, body } = notificationOpen.notification;
this.showAlert(title, body);
});
const notificationOpen = await firebase.notifications().getInitialNotification();
if (notificationOpen) {
const { title, body } = notificationOpen.notification;
this.showAlert(title, body);
}
this.messageListener = firebase.messaging().onMessage((message) => {
//process data message
console.log(JSON.stringify(message));
});
}
componentWillUnmount() {
this.notificationListener();
this.notificationOpenedListener();
}
【问题讨论】:
-
您为什么要向此时正在使用您的应用的用户发送通知?这似乎是一种非常烦人的用户体验。如果您想在您的应用程序使用期间收到某种通知,请尝试实现某种应用程序内通知,该通知会在应用程序使用期间出现一些自然停顿
标签: android firebase react-native notifications