question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I am not able to differ background push notification from foreground push notification

See original GitHub issue

Hello.

I have the plugin implementation just like the following.

PushNotifications.register();

PushNotifications.addListener('registration', (token: PushNotificationToken) => {
  // registering token on my backend
});

PushNotifications.addListener('registrationError', (error: any) => {
  console.log('error on register ', JSON.stringify(error));
});

PushNotifications.addListener('pushNotificationReceived', (notification: PushNotification) => {
  // receive push notification (opened application)
  console.log('notification', notification.data);
});

PushNotifications.addListener('pushNotificationActionPerformed', (notification: PushNotificationActionPerformed) => {
  // never called
  console.log('notification action performed', notification);
});

When i receive the push notification with the app opened (foreground), my console.log is executed as expected. But, if the app is closed, when i tap the notification, the app become open, but none of ther listeners are fired.

Am i doing something wrong?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
oliverandersencoxcommented, Sep 26, 2019

@FinnBossen yes. If you add this to your capacitor config file:

"plugins": { "PushNotifications": { "presentationOptions": ["badge", "sound", "alert"] } }

then remove the options you wish to have disabled for foreground notifications.

https://capacitor.ionicframework.com/docs/apis/push-notifications

1reaction
LucasPMMcommented, Aug 27, 2019

@gusmarra now it’s working for me:

    PushNotifications.addListener('pushNotificationReceived', async(notification: PushNotification) => {
      console.log('Notification Inside APP', notification);
    });

    PushNotifications.addListener('pushNotificationActionPerformed', async(notification: PushNotificationActionPerformed) => {
      console.log('Notification Outside APP', notification);
    });
Read more comments on GitHub >

github_iconTop Results From Across the Web

Flutter Firebase foreground push notification not showing but ...
After struggling a lot with this I found the solution. The problem was that I was sending the message ...
Read more >
Firebase Notifications in Background & Foreground in Android
The problem you have now is that your onMessageReceived is ONLY called when the app is in foreground, if you app if is...
Read more >
Push Enablement and Subscription - Braze
Foreground push provides the ability to send regular visible push notifications to the foreground of a user's device. · Background push is available...
Read more >
Foreground services - Android Developers
Foreground services perform operations that are noticeable to the user. Foreground services show a status bar notification, so that users are actively aware ......
Read more >
Receive messages in a Flutter app - Firebase - Google
On iOS, if the user swipes away the application from the app switcher, it must be manually reopened for background messages to start...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found