这是我的查询。我已经在我的一个react-native应用程序中实现了sendbird sdk,用于聊天实现。我正在尝试实现推送通知。我已经使用react-native-firebase作为firebase推送通知,如sendbird的文档中描述的那样。现在的问题是,当应用程序处于前台时,我的Android应用程序会收到推送通知。为此触发 OnMessageReceived() 侦听器。但是,当我的应用程序处于后台时,我不会收到来自 sendbird 的任何推送通知。不会触发任何 firebase 通知侦听器。
此外,当我尝试从firebase控制台发送通知时,我会收到前台和后台通知。
希望得到你们的回应,因为这可以帮助我成功实现此功能。
我的通知侦听器代码与此类似。但是,这里没有添加显示通知代码。
async componentDidMount() {
this.checkPermission();
this.createNotificationListeners(); //Notification listener
}
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);
}
/*
* Triggered for data only payload in foreground
* */
this.messageListener = firebase.messaging().onMessage((message) => {
//process data message
console.log(JSON.stringify(message));
});
}
showAlert(title, body) {
Alert.alert(
title, body,
[
{ text: 'OK', onPress: () => console.log('OK Pressed') },
],
{ cancelable: false },
);
}
}
梵蒂冈之花
茅侃侃
相关分类