-
Notifications
You must be signed in to change notification settings - Fork 275
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
Background mode notifications not receiving data in latest Firebase Cloud Messaging APIs and SDKs #266
Comments
We ran into the same issue: If we want the on notification handler to be called by clicking on the push notification when app is in backround we have to use the mixed payload with a special key-value pair { Did you try this? |
Thanks @ksch10bob. That does not work for me. When I add notId and click_action to my payload, I get an error like this:
To confirm, are you using the NEW FIREBASE messaging service? i.e. you are sending to
and not:
The new API has a different payload structure, and so far as I can tell does not allow the parameters the documentation for this plugin suggests adding. If you are using the new service, are you sending to a "topic" or a "token"? (the new payload requires a "message" field with that specified, e.g.
Thanks for your help and any further details. |
@viking2917 The FCM payload we give to AWS SNS has this structure
We think AWS SNS handles the wrapping of this payload into the new Sorry for not being specific enough about our exakt payload and Infrastructure. |
@ksch10bob. Thanks for your help! I have the click_action on the data object. When the app is in background, the app opens when the alert is tapped, but the on() notification function does not fire, so no chance to handle the custom data. If I put the click_action on the data{} field, or for that matter on the top level message{} object, the post to FCM service returns an invalid field error. So I think it has to go on the data{} field and that is what I am trying. Its good to know it works via SNS. Maybe I will try to set that up and then wireshark the payload or something. Just need to find the right magic dance :) Will post here if/when I figure it out :) |
@viking2917
The Hope that helps |
tried that too already :) |
@ksch10bob found it. You are correct, one does need the android section in the payload.
I had done that, but I also just discovered that somehow, not sure how, the following lines had been deleted from my AndroidManifest.xml, so the app would not start in background:
(I found this by running 'adb logcat' while the background notification was happening and watching for errors, in case helpful to anyone.) For anyone else with this issue, my full payload looks like:
(I am passing notId, as per documentation, although in my experiments it does not seem to be required) Thank you @ksch10bob !!! |
Hi @ksch10bob Sorry to highlight this closed issue, but we are using SNS also, and I was wondering how your experience was, switching from the old apikey, to the new json method of auth. Was it painless? |
@ksch10bob may have more SNS-specific info. My server side is in PHP and I found this StackOverflow answer worked pretty much as-is for me, in converting to the new API: https://stackoverflow.com/a/75482555. May be helpful. |
Hi @sithwarrior |
Bug Report
As noted in (#257), Firebase Cloud Messaging is obsoleting the old way of sending notifications and as of June 2024 will require an upgrade to v1 (https://firebase.google.com/docs/cloud-messaging/migrate-v1)
The documentation for this plugin states that in order for the on('notification') handler to be triggered, one must omit the "data" section of the message payload and instead use the "notifications" field. This is the only way to handle custom data to be passed to an application when it is in background mode and receives a notification.
My app works correctly when used with the legacy endpoint for FCM (https://fcm.googleapis.com/fcm/send), and receives custom data used to process the notification. When using the new FCM endpoint and associated new auth methodology (e.g. https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send), the app notifications correctly receive the custom data when the app gets a notification in foreground, but NOT when the app is in background.
Google's documentation says the message payload should look more or less as follows:
Whereas this documentation (https://github.com/havesource/cordova-plugin-push/blob/master/docs/PAYLOAD.md#notification-vs-data-payloads)_ says that to trigger the on('notification') from a background notification one should effectively do this:
thereby omitting the "data" field of the message.
In the old FCM, this works. In the new FCM, not only does the on('notification') not get triggered, but the notification displayed to the user has no title or body (because the "notifications" were not specified.)
Therefore it seems impossible to receive custom data from a background notification.
Has anyone successfully done this?
Expected Behaviour
Background notifications should invoke the on('notification') handler
Actual Behaviour
Background notifications, when used with the latest FCM V1 HTTP APi, do not raise the on('notification') handler
Reproduce Scenario (including but not limited to)
Steps to Reproduce
Platform and Version (eg. Android 5.0 or iOS 9.2.1)
(Android) Device Vendor (e.g. Samsung, HTC, Sony...)
cordova info
PrintoutCordova Packages:
Project Installed Platforms:
Project Installed Plugins:
Environment:
android Environment:
ERROR: Command failed with exit code 1: avdmanager list target
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
at com.android.repository.api.SchemaModule$SchemaModuleVersion.(SchemaModule.java:156)
at com.android.repository.api.SchemaModule.(SchemaModule.java:75)
at com.android.sdklib.repository.AndroidSdkHandler.(AndroidSdkHandler.java:81)
at com.android.sdklib.tool.AvdManagerCli.run(AvdManagerCli.java:213)
at com.android.sdklib.tool.AvdManagerCli.main(AvdManagerCli.java:200)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 5 more
ios Environment:
Xcode 15.1
Build version 15C65
Project Setting Files:
--- Start of Cordova JSON Snippet ---
{
"plugins": {
"cordova-plugin-email-composer": {},
"cordova-clipboard": {},
"cordova-plugin-camera-preview": {
"ANDROID_SUPPORT_LIBRARY_VERSION": "26+"
},
"cordova-plugin-sign-in-with-apple": {},
"cordova-plugin-inappbrowser": {},
"cordova-plugin-app-version": {},
"cordova-plugin-device": {},
"cordova-plugin-androidx-adapter": {},
"cordova-plugin-chooser": {},
"cordova-plugin-androidx": {},
"cordova-plugin-jitsi-meet-sdk": {},
"cordova-plugin-network-information": {},
"cordova-plugin-ionic-keyboard": {},
"cordova-plugin-file": {
"ANDROIDX_WEBKIT_VERSION": "1.4.0"
},
"cordova-plugin-x-socialsharing": {},
"cordova-sms-plugin": {},
"cordova-plugin-contacts": {},
"branch-cordova-sdk": {},
"cordova-plugin-fbsdk": {
"APP_ID": "",
"APP_NAME": "",
"FACEBOOK_ADVERTISER_ID_COLLECTION": "false",
"CLIENT_TOKEN": "",
"FACEBOOK_URL_SCHEME_SUFFIX": " ",
"OTHER_APP_SCHEMES": " ",
"FACEBOOK_AUTO_LOG_APP_EVENTS": "true",
"FACEBOOK_HYBRID_APP_EVENTS": "false",
"FACEBOOK_ANDROID_SDK_VERSION": "14.1.1",
"FACEBOOK_IOS_SDK_VERSION": "14.1.0",
"FACEBOOK_BROWSER_SDK_VERSION": "v14.0"
},
"cordova-plugin-camera": {
"ANDROIDX_CORE_VERSION": "1.6.+"
},
"@havesource/cordova-plugin-push": {
"ANDROIDX_CORE_VERSION": "1.6.+",
"FCM_VERSION": "23.+",
"IOS_FIREBASE_MESSAGING_VERSION": "~> 8.1.1"
},
"cordova-plugin-purchase": {},
"cordova-plugin-ionic-webview": {},
"cordova-plugin-splashscreen": {},
"phonegap-plugin-barcodescanner": {
"ANDROID_SUPPORT_V4_VERSION": "27.+"
}
},
"platforms": [
"browser",
"android"
]
}
--- End of Cordova JSON Snippet ---
Sample Push Data Payload
Sample Code that illustrates the problem
Logs taken while reproducing problem
The text was updated successfully, but these errors were encountered: