Open trashbytes opened 6 years ago
@EddyVerbruggen any idea?
Not really. Perhaps move that init logic out of app.js, and keep the require of the plugin in there.
You mean moving the whole firebase.init() out of app.js but still leaving require('nativescript-plugin-firebase')?
yes..
This does not work. Is it even remotely possible that onMessageReceivedCallback is called when the app is suspended? Or do I have to use 'notification' instead of 'data' if I want to receive notifications in that state?
@trashbytes I searched about that problem and found that firebase won't notify your app for a new notification if user closed the app by swiping. They say that user closes the app consciously if he is swiping it and they respect that. So, they don't notify your app. I think there is nothing else to do about that.
+1
@erkanarslan I do not believe this is true. Using the Quickstart Android demo (https://github.com/firebase/quickstart-android/blob/master/messaging/README.md) I am able to get onMessageReceived() even after swiping the app and from there I can build local notifications to show the user.
On the other hand, even with the latest 6.20 nativescript plugin, onMessageReceived() will not be called for me once I swipe the app. My manifest is identical to the one from Android Quickstart and get the same behavior as @trashbytes.
@EddyVerbruggen Is this the expected behavior and if so why does it deviate from original FCM behavior? I have replicated this using the demo and a new app with the plugin installed. Devices used : s8, One plus 3T, Pixel and a Moto on OS versions 24 & 26.
Thanks for sharing @KkevinLi ! Please keep us updated if you make any advancements regarding this. For us it's not currently a priority but still on the list of things which we want to get working so that we can achieve richer notifications.
@KkevinLi any news on this?
I'm experiencing this issue too. I've also tried to create a fresh NGx blank project to test it in a clean environment, but the issue still occurs.
Exactly how explained by @trashbytes. In my opinion, according to what the documentation states, we should be able to reach that callback even if the app is intentionally closed by the user, with the only difference that no visual notification will be shown in the tray.
An interesting fact is that when using the nativescript-background-geolocation-lt
library, without enabling the sync but setting the service as foreground, if I send the notification with only the data payload (no title or body) works perfectly even with the app closed.
But this is a paid library and a bit huge as "workaround" since it introduces a lot of other "headaches".
@EddyVerbruggen I'm kinda stuck here 😅. Can we hope in a fix or at least a review of the problem by you or should we look for other solutions?
I'd love to help somehow, but the fact that I'm relying on Nativescript proves my noobishness on native code 😔
Hi. Is there any update on this?
Hi @EddyVerbruggen , I got the same issue. It is working perfectly when the app in Background or in Foreground but when the app exit then i receive nothing.
Thank you!
@dangersvn If you are sending a data message and the application is closed, you won't get a notification in notification tray. Try sending a notification message. If you are already sending a notification message, some devices seems to be preventing FCM messages to preserve the battery. Try with another device. If you are trying with an iPhone simulator, as far as I know you cannot get a notification for ios simulators.
Hi @erkanarslan Thank you very much for your feedback! I tried with samsung s8 device + firebase + postman to verify the different between the Data message and Notification message and exactly as you described. I have not tested with iOS simulator yet so no feedback. In my case i have to deal with Data message, since the app depends on a third party backend which always using Data message to send PN via firebase to users while he/she offline. In case can't modify the third party backend then i need to use a service that is running on background even when the app is closed to deal with Data message.
@erkanarslan When my app is closed and I send a notification message I do receive the notification in the notification tray, but the onMessageReceivedCallback() is not called (I know this since my console.log statement did log anything). Is it the desired behaviour ?
@hkurma This the normal behavior. When you tap the notification, onMessageReceivedCallback() should be called.
Still don't have any concrete solution to this problem?
The onMessageReceivedCallback handler works just fine when the app is running in foreground or when I minimize it. Whenever I close it, for example by swiping it from the recents, it will not work anymore.
When it's in this state the only notifications that come through (to the tray) are these kind:
But what I need is this:
However the app only receives them after launching the app.
This line is already active in the include.gradle file:
Both services are enabled in AppManifest.xml:
onMessageReceivedCallback is initialized directly in the .init() function in app.js. I'm sending to a topic which the user subscribes to when he logs in.
Other things that might be useful to know for debugging: I've also added these parameters