在Android上的本机应用程序中,当我在调试模式,前台和后台运行我的应用程序时,一切都工作正常,两个推送通知都没有任何错误 . 但是当我生成签名的APK文件时,只有后台推送接收并且前台推送没有收到 .
我检查了android调试(Logcat),我可以看到通知从Firebase收到罚款,而不是在前台显示 .
这是我的app.js代码,这段代码正常运行 .
// Firebase Cloud Messages Start
async componentDidMount() {
const notificationOpen: NotificationOpen = await firebase
.notifications()
.getInitialNotification();
if (notificationOpen) {
const action = notificationOpen.action;
const notification: Notification = notificationOpen.notification;
var seen = [];
alert(
JSON.stringify(notification.data, function(key, val) {
if (val != null && typeof val == "object") {
if (seen.indexOf(val) >= 0) {
return;
}
seen.push(val);
}
return val;
})
);
}
const channel = new firebase.notifications.Android.Channel(
"test-channel",
"Test Channel",
firebase.notifications.Android.Importance.Max
).setDescription("My apps test channel");
// Create the channel
firebase.notifications().android.createChannel(channel);
this.notificationDisplayedListener = firebase
.notifications()
.onNotificationDisplayed((notification: Notification) => {
// Process your notification as required
// ANDROID: Remote notifications do not contain the channel ID. You will have to specify this manually if you'd like to re-display the notification.
}); this.notificationListener = firebase
.notifications()
.onNotification((notification: Notification) => {
// Process your notification as required
notification.android
.setChannelId("test-channel")
.android.setSmallIcon("ic_launcher");
firebase.notifications().displayNotification(notification);
});
this.notificationOpenedListener = firebase
.notifications()
.onNotificationOpened((notificationOpen: NotificationOpen) => {
// Get the action triggered by the notification being opened
const action = notificationOpen.action;
// Get information about the notification that was opened
const notification: Notification = notificationOpen.notification;
var seen = [];
alert(
JSON.stringify(notification.data, function(key, val) {
if (val != null && typeof val == "object") {
if (seen.indexOf(val) >= 0) {
return;
}
seen.push(val);
}
return val;
})
);
firebase
.notifications()
.removeDeliveredNotification(notification.notificationId);
});}
componentWillUnmount() {
this.notificationDisplayedListener();
this.notificationListener();
this.notificationOpenedListener();
}
// END
我也收到这两个错误:
Could not find class ‘android.app.NotificationChannelGroup’, referenced from method io.invertase.firebase.notifications.RNFirebaseNotificationManager.parseChannelGroupMap
Could not find class ‘android.app.NotificationChannel’, referenced from method io.invertase.firebase.notifications.RNFirebaseNotificationManager.parseChannelMap