Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with notification.data being empty in Notifee #1103

Open
dieptang opened this issue Sep 20, 2024 · 5 comments
Open

Issue with notification.data being empty in Notifee #1103

dieptang opened this issue Sep 20, 2024 · 5 comments

Comments

@dieptang
Copy link

I am encountering an issue with the notification.data object being empty when receiving notifications in my React Native application. Here are the details:

Notifee Version: 9.0.0
React Native Version: 0.73.9

Issue Description:
When I send a notification with both notification and data payloads from my PHP server, the data field in the notification is empty when handling the notification click event in Notifee.

Example FCM Payload Sent from Server:

{
  "notification": {
    "title": "New Booking",
    "body": "You have a new booking request"
  },
  "data": {
    "bookingId": "12345",
    "otherInfo": "Some info"
  }
}

Expected Behavior:
I expect the notification.data object to contain the keys bookingId and otherInfo when clicking on the notification.

Current Behavior:
The notification.data object is empty when the notification is clicked.

useEffect(() => {
        return notifee.onForegroundEvent(({ type, detail }) => {
            switch (type) {
                case EventType.DISMISSED:
                    console.log('User dismissed notification', detail.notification);
                    break;
                case EventType.PRESS:
                    console.log('User pressed notification', detail.notification);
                    break;

                case EventType.DISPLAY:
                    // Handle notification display event (if applicable)
                    console.log('Notification Displayed:', detail.notification);
                    break;
                case EventType.BACKGROUND:
                    // Handle background event if needed
                    console.log('Notification Background Event:', detail.notification);
                    break;
                default:
                    console.log('Other Event:', type);
            }
        });
    }, []);

I would appreciate your assistance in resolving this issue.

Thank you!

@KhoaNguy3n
Copy link

I am also experiencing the same issue!

Notifee Version: 9.1.1
React Native Version: 0.73.7

Copy link

github-actions bot commented Nov 8, 2024

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

@rranjan14
Copy link

Experiencing the same issue in iOS as well.

Notifee Version: ^9.1.2
React Native Version: ~0.75.4
@react-native-firebase/messaging: ^21.4.0

@LinhNguyen1059
Copy link

I have the same issue, and after spending 2 hours figuring it out, you need to set the data when you display a notification so that when you press the notification, you can get back the data you've passed.

messaging().onMessage(remoteMessage => {
  onMessageReceived(remoteMessage);
});

const onMessageReceived = async remoteMessage => {
  const {notification, data} = remoteMessage;
  
  await notifee.displayNotification({
    title: notification.title,
    body: notification.body,
    android: {
      channelId: CHANNEL_ID,
      importance: AndroidImportance.HIGH,
      smallIcon: 'noti_icon',
      pressAction: {
        id: 'default',
        launchActivity: 'default',
      },
      lightUpScreen: true,
    },
    data, // need to set the data here
  });
};

@fazzaamiarso
Copy link

fazzaamiarso commented Nov 21, 2024

I have the same issue, and after spending 2 hours figuring it out, you need to set the data when you display a notification so that when you press the notification, you can get back the data you've passed.

messaging().onMessage(remoteMessage => {
  onMessageReceived(remoteMessage);
});

const onMessageReceived = async remoteMessage => {
  const {notification, data} = remoteMessage;
  
  await notifee.displayNotification({
    title: notification.title,
    body: notification.body,
    android: {
      channelId: CHANNEL_ID,
      importance: AndroidImportance.HIGH,
      smallIcon: 'noti_icon',
      pressAction: {
        id: 'default',
        launchActivity: 'default',
      },
      lightUpScreen: true,
    },
    data, // need to set the data here
  });
};

I have the same issue of data not being shown on any handlers when pressed. I'll try this solution and get back

UPDATE: This should be in the documentation. Added the data props and it worked on Foreground and Kill State. However, still having issue when app is running on background.

Notifee Version: 9.1.2
React Native Version: 0.76.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants