我目前正在尝试在基于react native的应用程序中实现推送通知。我能够接收从Firebase控制台云消息传递功能发送的通知,但是我面临两个问题
当我的应用程序在后台运行时,我可以收到 仅通知。然后当它在前景时,我收不到 我的通知抽屉中的通知。
当我单击通知时,其通知字段中不包含任何内容,而不是文本,既不是标题也不是其他内容
async componentDidMount() {
await request_runtime_permission()
await this.checkPermission();
await this.createNotificationListeners();
}
async createNotificationListeners() {
this.notificationListener = await firebase.notifications().onNotification((notification) => {
console.log(notification);
const { title, body } = notification;
console.log(notificationOpen.notification)
this.showAlert(title, body);
});
this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen) => {
alert('onNotificationOpened')
console.log(notificationOpen)
const title = notificationOpen.title
const body = notificationOpen.body
});
this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen) => {
alert('onNotificationOpened')
console.log(notificationOpen)
const title = notificationOpen.title
const body = notificationOpen.body
console.log('title->', title, 'body->', body)
this.showAlert(title, body);
});
const notificationOpen = await firebase.notifications().getInitialNotification();
if (notificationOpen) {
// alert('getInitialNotification')
const { title, body } = notificationOpen.notification;
console.log('title->', title, 'body->', body)
this.showAlert(title, body);
}}
我正在使用以下版本
"react-native-firebase": "^5.1.1",
"react-native": "^0.55.4",
及以下依赖性
'com.google.firebase:firebase-core:16.0.4'
"com.google.firebase:firebase-messaging:17.3.4"
"com.google.android.gms:play-services-auth:16.0.1"
"com.google.android.gms:play-services-base:16.0.1"