React-native-push-notification: Notification Arrives Two Times

Created on 22 Feb 2019  路  7Comments  路  Source: zo0r/react-native-push-notification

Hello, I am in the midst of porting Native app to React Native and I am facing this issue on React Native side using this library. On my React Native app, the notification arrives two times. This is not an issue on the native app.

This is my OnNotification body

onNotification: function(notification) {
    if (notification.foreground) {
        console.log("NOTIFICATION:", notification);
     }
    PushNotification.localNotification({
        message: notification.alertBody
    });
    console.log(notification);
    if (Platform.OS == "ios") {
        notification.finish(PushNotificationIOS.FetchResult.NoData);
     }
},

_Note: I am doing a localNotification call because the server which is not under my control sends alertBody key instead of message so when my app is in background notification never arrives. However, when I send a notification using a service like pushtry it works. So I suspected that this happens because the key is wrong._

This is what I get when I console log the notification object

{
    foreground: false,
    finish: [
        Function: finish`
    ],
    'google.delivered_priority': 'normal',
    'google.sent_time': 1550835432097,
    'google.ttl': 2419200,
    'google.original_priority': 'normal',
    alertBody: 'Lamp has been turned OFF manually',
    deviceStatus: 'OFF',
    deviceScheduleStatus: 'false',
    userInteraction: false,
    id: '888769420',
    badge: '1',
    sound: 'default',
    actionKey: 'DEVICE_ACK_6469',
    'google.message_id': '0:1550835432107983%dcba0139f9fd7ecd',
    actionPending: 'false',
    deviceId: '6469'
}
{
    foreground: false,
    finish: [
      Function: finish
    ],
   alertBody: 'Lamp has been turned OFF manually',
   deviceStatus: 'OFF',
   deviceScheduleStatus: 'false',
   userInteraction: false,
   id: '898772892',
   badge: '1',
   sound: 'default',
   actionKey: 'DEVICE_ACK_6469',
   actionPending: 'false',
   deviceId: '6469'
}

Most helpful comment

please check your AndroidManifest.xml try to remove receiver named com.google.android.gms.gcm.GcmReceiver and service named com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerServiceGcm but keep the receiver named com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher and service named com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService, see if the notification still works and only received once

All 7 comments

Funny, I also have this problem and it started yesterday. My logs are just about the same as yours

same issue, need to fix asap

that its because when an notification arrives you call another notification in your code

    PushNotification.localNotification({
        message: notification.alertBody
    });

are you call the notification in componentDidMount or some fuction?

that its because when an notification arrives you call another notification in your code

    PushNotification.localNotification({
        message: notification.alertBody
    });

are you call the notification in componentDidMount or some fuction?

I'm not calling localNotification in onNotification but getting same issue

please check your AndroidManifest.xml try to remove receiver named com.google.android.gms.gcm.GcmReceiver and service named com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerServiceGcm but keep the receiver named com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher and service named com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService, see if the notification still works and only received once

please check your AndroidManifest.xml try to remove receiver named com.google.android.gms.gcm.GcmReceiver and service named com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerServiceGcm but keep the receiver named com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher and service named com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService, see if the notification still works and only received once

nice !

please check your AndroidManifest.xml try to remove receiver named com.google.android.gms.gcm.GcmReceiver and service named com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerServiceGcm but keep the receiver named com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher and service named com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService, see if the notification still works and only received once

This is the solution to this problem. Works, thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cidevant picture cidevant  路  3Comments

uendar picture uendar  路  3Comments

nguyenvanphuc2203 picture nguyenvanphuc2203  路  3Comments

ahmadallo1 picture ahmadallo1  路  3Comments

sungjinoh picture sungjinoh  路  3Comments