[英]react-native-firebase receiving notification when app in running
I'm implementing push notification using react-native-firebase. 我正在使用react-native-firebase实现推送通知。 So, I'm testing the cloud messaging. 因此,我正在测试云消息传递。 I could receive the notification when screen is off and in background. 当屏幕关闭且处于后台时,我会收到通知。 But, I couldn't receive notification when the app on running. 但是,当应用程序运行时,我无法收到通知。 Are there any problem in my code or do i need to add some code? 我的代码中是否有任何问题,或者我需要添加一些代码?
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();
}
Push Notifications cannot occur in App because that is actually contrary to it's a purpose. 推送通知无法在App中发生,因为这实际上与它的目的相反。 A reasonable definition of a push notification is the delivery of information from a software application to a computing device without a specific request from the client. 推送通知的合理定义是无需客户端的特定请求即可将信息从软件应用程序传递到计算设备。 During app use, the client would be making specific requests to the server. 在使用应用程序期间,客户端将向服务器发出特定请求。 You should handle the notifications differently like using a numbered Icon for example. 您应该以不同方式处理通知,例如使用带编号的图标。 You could also explore Firebase In-App Messaging for a more engaging experience. 您也可以探索Firebase应用内消息传递以获得更有吸引力的体验。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.