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

Sending Custom Data in FCM not working #212

Open
imarc7 opened this issue Jul 29, 2024 · 4 comments
Open

Sending Custom Data in FCM not working #212

imarc7 opened this issue Jul 29, 2024 · 4 comments

Comments

@imarc7
Copy link

imarc7 commented Jul 29, 2024

Sending custom data with FCM is not working. When trying to log the notification received in Expo React Native, no custom data is received.
Here's the code:

const settings = {
  fcm: {
        appName: 'xxxxx',
        serviceAccountKey: jsonKey, 
        credential: null,
   }
}
const push = new PushNotifications(settings);
const deviceToken = 'xxxxxxxxxx';
const data = {
      title: 'XXXX',
      body: 'Message',
      custom: {
        // Additional data to send with the notification for android
        name: 'test'
      },
    };
push.send(deviceToken, data, (error: Error, result: any) => {
});

The notification is received but the custom param "name" is not there.

@hajjarjoseph
Copy link

Same issue here...

@arnaudambro
Copy link

seems to be a problem with expo, doesn't it ?

expo/expo#28656

@alex-friedl
Copy link
Collaborator

Hey guys. Let us know if you can confirm that this is an issue with expo.
Otherwise we'd be happy to accept PRs for fixing whatever issue this is for your use-case.

@eikaramba
Copy link

i experienced the same problem. i am not using Expo just nativescript for my app.

The problem seems to be due to the migration of the new http api of FCM. my problem was that after migration it seems the data-only notification was not send anymore. Also the android_channel_id property is now just channel_id (although i am currently not using it anymore thus you will not find it in the code below)

anyhow, this is working for me now:

const data = {
                    collapseKey: Math.random().toString().replace('0.', ''),
                    title: 'test',
                    topic: 'all',
                    body: 'text',
                    priority: 'high',
                    custom: {
                        id:'123',
                    },
                    fcm_notification: {
                    },
                    icon: 'notification_icon',
                    sound: 'test.wav',
                    category: 'alarm',
                    truncateAtWordEnd: true,
                    pushType: 'alert',
                };
                const pushResult = await push.send(result.user.fcmToken, data);

strangely i need to put the empty fcm_notification object into it, because otherwise https://github.com/appfeel/node-pushnotifications/blob/master/src/utils/tools.js#L77 will create these properties for a notification message it seems and then my custom messaging service is not invoked on the android client side. Really strange, but this was doing the trick for me. hopefully this also helps others

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