zo0r / react-native-push-notification

React Native Local and Remote Notifications
MIT License
6.77k stars 2.05k forks source link

How to receive push notifications ONLY in background state. #1758

Open plaksin-a opened 3 years ago

plaksin-a commented 3 years ago

Hi all! I am using an example from the readme and as result, I always receive push-notifications no difference the app in an active state or background state, but I would like to show notifications only when the app in the background state. Can you help me, where I did a mistake? I wrapped the next code in a function and call it in redux-saga.

  PushNotification.configure({
    onRegister: function (payload) {
      console.log('TOKEN:', payload);
    },

    onNotification: function (notification) {
      console.log('onNotification NOTIFICATION:', notification);
      notification.finish(PushNotificationIOS.FetchResult.NoData);
    },

    onAction: function (notification) {
      console.log('onAction NOTIFICATION:', notification);
    },

    onRegistrationError: function (err) {
      console.error(err.message, err);
    },

    permissions: {
      alert: true,
      badge: true,
      sound: true,
    },

    popInitialNotification: true,
    requestPermissions: true,
  });
Dallas62 commented 3 years ago

Hi @plaksin-a You can take a look to:

https://github.com/zo0r/react-native-push-notification/blob/master/trouble-shooting.md#about-notifications

Regards,

axeljeremy7 commented 3 years ago
<!-- Change the value to true to enable pop-up for in foreground (remote-only, for local use ignoreInForeground) -->
        <meta-data android:name="com.dieam.reactnativepushnotification.notification_foreground"
                   android:value="false"/>

I think this should work