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

bug: notificationReceived called instead of notificationActionPerformed #793

Open
5 of 17 tasks
stevecohenfr opened this issue Jan 8, 2025 · 6 comments
Open
5 of 17 tasks

Comments

@stevecohenfr
Copy link

stevecohenfr commented Jan 8, 2025

Plugin(s)

  • Analytics
  • App
  • App Check
  • Authentication
  • Crashlytics
  • Cloud Firestore
  • Cloud Functions
  • Cloud Messaging
  • Cloud Storage
  • Performance
  • Remote Config

Version

6.3.1

Platform(s)

  • Android
  • iOS
  • Web

Current behavior

When my app is in the background and receives a notification, the notificationReceived event is correctly triggered with the expected data.

However, when I click on the notification, the notificationReceived event is triggered again instead of the notificationActionPerformed event. This behavior prevents me from handling notification actions as expected.

Expected behavior

notificationReceived should be triggered when the notification is received in the background.
notificationActionPerformed should be triggered when the notification is clicked.

Reproduction

n/a

Steps to reproduce

async addListeners() {
    FirebaseMessaging.removeAllListeners().then(async () => {
      console.log('[Notifications Push] Listening "tokenReceived" event');
      await FirebaseMessaging.addListener('tokenReceived', async event => {
        console.info('[Notifications Push] Registration token: ', event.token);
        const addResponse = await this.fcmService.addFcmToken(event.token);
        console.log('[Notifications Push] Ajout du token réussi :', addResponse);
      });

      console.log('[Notifications Push] Listening "notificationReceived" event');
      await FirebaseMessaging.addListener('notificationReceived', event => {
        console.log('[Notifications Push] notificationReceived', JSON.stringify(event));
        const data = (event.notification.data as any);
        this.handleNotificationClicked(data);
      });

      console.log('[Notifications Push] Listening "notificationActionPerformed" event');
      await FirebaseMessaging.addListener('notificationActionPerformed', event => {
        console.log('[Notifications Push] notificationActionPerformed', {event});
        const data = (event.notification.data as any);
        this.handleNotificationClicked(data);
      });
    });
  }

addListeners is called is the ngAfterViewInit from my main component

Other information

No response

Capacitor doctor

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 6.2.0
  @capacitor/core: 6.2.0
  @capacitor/android: 6.2.0
  @capacitor/ios: 6.2.0

Installed Dependencies:

  @capacitor/cli: 5.7.5
  @capacitor/core: 5.7.5
  @capacitor/android: 5.7.5
  @capacitor/ios: 5.7.5

Before submitting

  • I have read and followed the bug report guidelines.
  • I have attached links to possibly related issues and discussions.
  • I understand that incomplete issues (e.g. without reproduction) are closed.
@stevecohenfr stevecohenfr added bug/fix Something isn't working needs: triage labels Jan 8, 2025
@robingenz
Copy link
Member

Thank you for reporting that. I will take a look as soon as i have time. Feel free to create a PR if you would like to take a closer look.

@wif70068
Copy link

wif70068 commented Feb 10, 2025

I encountered the same issue, and the solution was similar to this PR. The fix was to remove handleApplicationNotifications: false from the Capacitor config, as it was a leftover from the OneSignal plugin. Like others in the linked PR, I initially looked in the wrong place and was puzzled why the didReceive and willPresent methods in the FirebaseMessaging class weren’t being triggered. Probably makes sense to add this to the documentation.

@robingenz
Copy link
Member

@stevecohenfr Please check if this also the issue in your case.

@stevecohenfr
Copy link
Author

@robingenz

Hello, I try to fix with this PR but not sure on how to deal with it.
Here is what I've done :

git clone https://github.com/capawesome-team/capacitor-firebase.git
cd capacitor-firebase

# I'm using version 6.3.1 for my project
git checkout tags/@capacitor-firebase/[email protected] -b messaging-6.3.1
git fetch origin pull/267/head:firebase-messaging-patch
git cherry-pick 977464855ee52a27ad950c62cde4fe7baa8f37db

And

npm install
npm run build
cd packages/messaging
npm link

And in my project to use the local version of this dependency

npm link @capacitor-firebase/messaging

Then I tried to run on iOS :

npx cap sync
npx cap run ios

And I've this error when I try to register  listeners : plugin is not implemented on ios

Did I miss something ?

Thanks

@robingenz
Copy link
Member

I've implemented this plugin yesterday in a clients projects without any issue. Both listeners are called correctly. It should therefore be a configuration issue on your side. Please provide a minimal, reproducible example.

Copy link
Contributor

This issue has been labeled as needs: reproduction. This label is added to issues that need a code reproduction.

Please provide a Minimal, Reproducible Example using this template in a public GitHub repository so we can debug the issue.

If you have already provided a code snippet and are seeing this message, it is likely that the code snippet was not enough for us to reproduce the issue.

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

No branches or pull requests

3 participants