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

Call .on('notification') when app is in background #67

Open
esanchezvz opened this issue Nov 20, 2020 · 3 comments
Open

Call .on('notification') when app is in background #67

esanchezvz opened this issue Nov 20, 2020 · 3 comments

Comments

@esanchezvz
Copy link

Bug Report

Disclaimer - this is not a bug report. I just need some guidance to get a feature involving this plugin to work correctly.

I'm building an app with Ionic + Cordova + Angular I and we have a feature that needs to redirect users to a specific screen when clicking on a push nootification. We are using firebase cloud messaging to send out the notifications.

Expected Behaviour

We send out a notification with a new post created and the user clicks on that notification from the tray and it should open the app + navigate to that specific screen.

Actual Behaviour

This works perfectly whenever the app is running in the foreground, but when my app is closed or in the background the
event handler is not called.

Reproduce Scenario (including but not limited to)

To reproduce this you would just have to add this pluggin and send out a push notification with a payload to see that the events are not firing.

Sample Push Data Payload

{
  "sound": "default",
  "title": "My notification title",
  "message": "Some message to tell the user",
  "additionalData": {
    "path": "post/1096",
    "color": "#fff",
    "dismissed": false,
    "coldstart": false,
    "foreground": false
  }
}

I was looking through the repo and found that if I send a notification with a payload it would not trigger the .on('notification') event handler, but it also says that if I add the content-available: "1" parameter to the payload it would trigger all events in the background. However, I can't test if by adding content-available it would work or how it would behave since I don't have control over the backend (I've already told this to the backend team) but apparently it may take a while to add this for me to test. So I was wondering if you could tell me if that would be the correct approach or how should I go about getting this feature to work.

I've already added deeplinks logic to handle app routing but I can't get the .on('notification') event to run when my app is on the background. Is there a way to do this?

@stardevrk
Copy link

@esanchezvz Please help me. What ionic-native wrapper did you use with this cordova plugin. I am working on the ionic project with this plugin. But I can not use this plugin fully without the ionic native wrapper.
Thanks.

@Heshyo
Copy link

Heshyo commented Jan 13, 2021

@stardevrk This plugin should be compatible with npm i @ionic-native/push.

@francobasaglia
Copy link

francobasaglia commented Apr 7, 2021

@stardevrk @esanchezvz to execute .on('notification') callback, when app isn't on foreground, you should add "content-available": "1" on notification payload. The behaviour could not be the same on iOS and Android.
Take a look here:

https://github.com/havesource/cordova-plugin-push/blob/master/docs/PAYLOAD.md#ios-behaviour

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

4 participants