-
Notifications
You must be signed in to change notification settings - Fork 564
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: PushNotifications not triggering code within pushNotificationReceived
(data notification)
#200
Comments
I've seen it work in the past, but I confirm is not working anymore. Once I open the app I get the notification data, but not while it's killed. |
Is there any update regarding to this bug (or any workaround), otherwise planning to write plugin of my own, this is becoming real pain, as the app is not running (not forcefully killed), it is not performing any action inside 'pushNotificationReceived' event listener. One more request, if setLargeIcon can be added to LocalNotification plugin as well. |
@2bona this is indeed not the place to ask. Nevertheless, you can use the api as needed without needing typescript... The api is exactly the same. |
thank you very much, its just as u said the same thing |
Any update please ? |
Still waiting... |
Guys not to sound like a tool but push notifications were one of the main things that led me to choose Capacitor for my project. The fact that they're not working as intended is a big let down. The behaviour on my end sounds the same as other people noted above. When the app is closed or running in the background the My dependencies are:
I'm sending notifications from my server via FCM. |
Oh I should note that sending notifications via the Firebase cloud messaging test page works as intended. It's only when my actual functions code is sending notifications that |
Sorry if I sounded like a jerk in my original post. I'm really impressed with Capacitor I was just frustrated. |
Same problem, data push notification is not received when app is in background, only foreground and closed if i use notification type. "@capacitor/android": "^2.0.2", We have a booking app, this problem is lethal because we have to confirm payments. Hope you will fix the problem. Tests made on a Samsung S7 Edge. Best regards. |
So I don't know if I was having the exact same issue as everyone else here is, but here's how I solved it. My issue was with iOS and I'm using FCM.
I also created a new local plugin I just added a file called remote.swift to my project:
Finally from the TypeScript side of things I needed to register an OnRemoteNotification listener:
While not data notifications, I also had issues with regular alert push notifications while my app was in the background. I solved these issues by 1) registering a listener with |
Just want to confirm the issue at my end. We are going to upgrade several apps from Ionic 3 + cordova to Ionic 5 + Capacitor but this issue needs to be fixed first. Foreground notifications works perfectly on both iOS and Android. A note on Android and background. I see in logcat that when the app goes in the background the app closes completely after less then a second. So it may be the case that if works in background but I have not been abel to test it.
@casper5822 Quick question. What do you mean by "and closed if i use notification type". Is there anything special we have to do to make it work when the app is closed? |
I use firebase and there are two types of push notifications: notification and data. Data notifications work if the app is in foreground or background |
@casper5822 Thanks for the quick reply. Okey, yes,then I understand. When I click the notification on Android when the app is closed I see the following i logcat: Is that a clue for anyone? |
Is anyone working on this issue? |
@spikeynick I have the same exact issue. DATA-ONLY message never triggered the "pushNotificationReceived" event on iOS. We spent days on this. Ended up doing basically the same thing as you did except more dirty, only for this scenario. Thanks for confirming the issue! |
I was struggling for a while with the same issue. I was using Amazon Pinpoint to send a notifications for Android. Once I changed "Standard Message" to "Raw Message" it actually worked in the foreground and background. This is the payload:
I hope that will help someone. |
Today i made some tests with this configuration: Data notifications work in So it seems working for me. I don't know on Ios |
If someone need a solution who works, switch to phonegap push plugin and send the notification with an API, in the post message dont use "notification" field, pass the title, body, and other fields of notifications in the "data" field. If you do that, it works. |
I have the same issue in version 2.2.0 . Actually when I open the app after a data notification was received (while the app was on the background) I can see the data (via an alert) but the listener is not triggered while on background/killed mode. Will there be a fix in future versions? |
Im having the same issues as many above, and perhaps its the way im implementing the plugin however I am receiving all notifications using FCM whether the app is killed, launched and in the background. But when the app is killed and the user receives a notification and then launches the app (opening from a hard close with splash screen launching etc.) I cannot grab the "getDeliveredNotifications()" to retrieve notification data. Specifically I am trying to grab the badge count for UI purposes. |
Just to let you know, I found the solution for our problem. Maybe it will help someone else. The problem was that we were adding |
Hello everyone, I don't know if my problem its the same, but I think this can be related and definitely something is wrong with the push notifications on capacitor 2, I'm using capacitor and all the dependencies on version 2.2.1. I'm just sending a simple message, without data and images and everytime when I sent a message my app crash in foreground and also in background, but only crash when I send a message from Firebase. I'm just running the tutorial on android and the same code base to test the notifications, but doesn't work for me I have other applications on capacitor 1.4 and works very well, but I can't make this works on capacitor 2.2.1 Crash report:
|
Hello everyone, I fix my problem reading the firebase repo and please feel free to try if this can solve your problems with push notifications: In my case the notification never arrived because the app crashes on background when I recive the message. this was a problem inside firebase-messaging:20.1.2 and is solved in 20.1.4 here is the source firebase/firebase-android-sdk#1339 I did this to fix the problem: change the version located in android/variables.gradle from 20.1.2 to 20.1.4
Then in android studio go to "Files / Sync Project with Gradle Files", remove your app from your device, compile again and works very well on background. I think the default version of firebase messaging will be updated on the next versions of capacitor, but that works for me. This is only my case, please feel free to try and thank you for your comments. |
@ivancduran Indeed it works well on background, but still it does not work when the app is killed. It is supposed to wake it up should it be a data notification. |
I tested it with the latest firebase messaging version (20.2.4) and capacitor (2.4.0), it is still not working, when the app is killed/closed. |
any update on this open bug, please? |
https://github.com/ionic-team/capacitor/issues/2401#issuecomment-652624407 |
@jcesarmobile do you plan to fix this in capacitor v2.x? |
2021 and the problem persists, pushNotificationReceived does not fire in the foreground or background. |
remote.swift in which folder did you create it? @spikeynick |
@anthonyjuarezsolis it is in the same directory as AppDelegate.swift |
Hey there, for anyone getting here, i recently created a Plugin which does support data Notifications: https://github.com/EinfachHans/capacitor-firebase-push :) |
For me it was a mistake how I perceived FCM messaging is working. Disclaimer: may not apply to the issue here, but some people browsing here like me could benefit... For me, too, background notifications where not working. I learnt the hard way that it was an error how I implemented sending the messages in the background. According to this explanation there is a difference between notifications and data messages. Data messages are not expected to be handled by Data messages are handled by the client, ie. when app in foreground. When App is in background, usually no background tasks are listening to messages (as I thought) but the operating system takes over. This is where Notifications come into play. All I needed to do is to extend my message payload to this in backend:
The data part is for handling in the foreground (client). Works like a charm, even if app is totally killed. |
@AntoniusGolly Hi, I have had mine configured this way since I started watching this issue. I cannot change the colour of the LED or even get the sound to be set. Unfortunately, it doesn't work for me. Even having the ability to add actions to the notification like mark as read for example. Just can't get it done. The idea behind it is that when the notification is received in the background and executes "pushNotificationReceived" you can then implement local notifications in order to manipulate the colour, sound and actions of the notification. At least that is what it is meant to do, but as this issue states, nothing is triggered on "pushNotificationReceived" I have always received the notification in the background. |
@AntoniusGolly are you getting the OnNotificationReceived event to trigger on iOS when your app is in the background? |
@spikeynick I've tried implementing your approach in capacitor v3 but haven't got it working. Have you migrated to v3? |
I also tried following Firebase's docs, they have an article on receiving notifications in the background on iOS but I can't get it working with capacitor: https://firebase.google.com/docs/cloud-messaging/ios/first-message |
@skotturi no we are still on v2 |
After digging into this quite a bit today, I discovered that the Capacitor It should be possible to also implement UIApplication's |
@kainosnoema I have been struggling with this for ages and not being a native Swift developer, I have been unable to get workarounds to function properly. Any insight on what you did/will do to implement this would be greatly appreciated! |
@kainosnoema I've also been struggling with wonky iOS notifications. Regular notifications come through fine, but trying to implement local notifications via push notifications to do actionable notifications is wonky. If you end up solving this, a fork would be much appreciated. |
@ajincentfit honestly we'll probably end up doing just that—I have quite a bit of native Swift experience so can pull it off with some time. Will keep you posted. I love Capacitor in most areas, so it's kind of wild to me that something so critical and core to mobile development has such poor support here at v3. 😢 |
Ok this needs to be fixed. Background notifications is a critical feature for pretty much any push notifications scenario... this plugin is almost useless without it...this has been my biggest hiccup with Capacitor 3. Everyone has to do workarounds to make this plugin work and almost a year later nothing has changed. |
Still not working :(
|
@kainosnoema did you ever find a solution for this?.. I've been trying to implement a custom IOS plugin to solve the issue but I'm not having any luck. |
@LouieSankey unfortunately no. We're still dealing with a reduced experience here. I have a feeling one of the reasons Ionic isn't fixing this is because Apple doesn't actually allow the embedded web view (WKWebView) to run or make network requests while in the background, so there's not much in the JS you could do with background push. I wish they'd clarify though as it's very confusing and surprising. Your best bet is to probably handle background push and do whatever fetching/processing you need to do on the native side, and pass it back to the web view when the app is foregrounded and restored. |
Looks like there is no solution for this as @theproducer closed it with a PR which added a doc claiming this issue is not going to be fixed. |
I'm receiving background notifications, but not foreground. The pushNotificationReceived listener is not kicking in. Any updates on this? |
@morsagmon I had given up on this but since my push notification token expired and I needed to find a method of refreshing it, it set me out to research this again. From recent research, it would appear that in order for this to work your push notifications need to be data only. When they are data only they are "silent". The app receives them but then you need to handle them with local notifications. Which isn't too much of an issue as this now gives you the ability to add action buttons to your notifications as well as many other cool features. Another thing to add is that it's best to not bother with the built-in ionic/capacitor PushNotifications plugin as this does not give you anyway to refresh a token. The only way for the user to refresh the token is to uninstall and reinstall the app. Not very good UX. So instead make use of @capacitor-firebase/messaging. This comes with two methods that you will use to refresh the token. DeleteToken() and getToken(). I am still in the process of implementing this but it all looks quite promising. |
@fromage9747 Thanks for the input. I have no problem with the token not being refreshed in the background. |
Has anyone found a solution? |
Yeah, forget about the built in push notifications from capacitor/Ionic. Use angular firebase messaging and only send data messages so that they are silent. These will work in the background and foreground. Then when the message is received, you launch a local notification through ionic which also gives you more functionality and control like action buttons. |
The following works for me.
And this captures a tap on a notification that was received when the app is in the background:
The only problem I still have is with background notifications - they are received, but only showing a small icon in the upper status bar of the receiving machine, not popping up a visible message. The user must swipe down to reveal notifications, and there it is - ready to be tappable. From what I learned, this is controlled by the visibility property of android in the notification payload, but I could not get this to work - here's my notification function in Firebase (triggered by RTDB insert record):
|
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out. |
Bug Report
A push notification send through firebase isn't triggering the code located within the
addEventListener
forpushNotificationReceived
.Capacitor Version
Affected Platform(s)
Current Behavior
Currently when a data notification is pushed through Firebase, to a device which is no longer in the foreground ( has been (non forcefully) killed by swiping it away in the recent application viewer):
The notification is handled by CapacitorFirebaseMessagingService#onMessageReceived yet it is never handled by the
pushNotificationReceived
within the application code (like it should according to the documentation).The reason for this is the fact that PushNotifications#sendRemoteMessage expects the
bridge
to be set within: PushNotifications#getPushNotificationsInstance. This is however never the case as the pluginload
method is not called as such the staticstaticBridge
is never assigned. And the call is never relayed down to the application Typescript code.Expected Behavior
I would expect the
getPushNotificationsInstance
method to initialize the application / load it so thestaticBridge
property is set. Otherwise the documentation will have to be updated to reflect the fact that listening forpushNotificationReceived
only works when the application is active and the user hasn't (none forcefully) killed the app by swiping it away within the recent application viewer.Sample Code
Notification we push to firebase:
Code within the
AppComponent
Other Technical Details
npm --version
output: 6.11.3node --version
output: 10.17.0Tested on two different devices:
Other Information
Might relate to: ionic-team/capacitor#1928 (comment)
The text was updated successfully, but these errors were encountered: