Android FCM推送通知不存在';应用程序在前台时不显示-反应本机
在Android上的react本机应用程序中,当我在调试模式下运行我的应用程序时,一切都正常工作,前台和后台推送通知都接收良好,没有任何错误。但当我生成签名的APK文件时,只接收后台推送,而不接收前台推送 我检查了android调试(Logcat),我可以看到Firebase发出的通知很好地接收到了,并且没有显示在前台 这是我的app.js代码,该代码正在运行Android FCM推送通知不存在';应用程序在前台时不显示-反应本机,android,firebase,react-native,firebase-cloud-messaging,Android,Firebase,React Native,Firebase Cloud Messaging,在Android上的react本机应用程序中,当我在调试模式下运行我的应用程序时,一切都正常工作,前台和后台推送通知都接收良好,没有任何错误。但当我生成签名的APK文件时,只接收后台推送,而不接收前台推送 我检查了android调试(Logcat),我可以看到Firebase发出的通知很好地接收到了,并且没有显示在前台 这是我的app.js代码,该代码正在运行 // Firebase Cloud Messages Start async componentDidMount() { const n
// 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
您好,您正在安卓O或更高版本的设备上测试吗?如果是,那么你必须为你的通知创建一个通知频道来显示。我已经在安卓4.4和8.0上测试了这段代码,但还没有收到通知。但这段代码在两台设备上的调试模式下都运行良好。您是在通知或数据对象中发送消息通知吗?很抱歉,我没有理解您的意思,我正在从Firebase控制台发送推送消息。您是在以下格式发送“数据”:{“标题”:“我要告诉您一个化学笑话”,“消息”:“但我知道我不会有任何反应”,“图像url:”}