首页 > 解决方案 > react-native-push-notification 前台通知

问题描述

我正在通过本机反应开发应用程序。
我需要发送一些带有推送通知的数据,但是在 android 中,当我收到通知时它会显示在屏幕上。
我配置了如下通知:

PushNotification.configure({

    onRegister: function(token) {
        Fetcher("userSetNotifToken",{notifToken:token.token},true);

    },
    onNotification: function(notification) {
        console.log(notification);
        if(platform  == 'ios') {
            if (notification.alert.extra !== undefined && notification.alert.extra.type == 'trip') {
                alert("sad");
            }
            notification.finish(PushNotificationIOS.FetchResult.NoData);
        }else{
            if (notification.data !== undefined && notification.data.type == 'trip') {
                Actions.reset("home", {trip: notification.data.trip});
            }
        }
    },
    senderID: "----",
    permissions: {alert: true, badge: true, sound: true},
    popInitialNotification: false,
    requestPermissions: true,
});

有什么办法可以禁用这个选项?

标签: react-native

解决方案


我在 react-native-push-notification 文件夹下的 node_modules 文件夹中找到了解决方案:

java/com/dieam/reactnativepushnotification/modules/RNPushNotificationListenerService.java

我改变了这个:

pushNotificationHelper.sendToNotificationCentre(bundle);

对此:

if (!isForeground) {
pushNotificationHelper.sendToNotificationCentre(bundle);
}

推荐阅读