Closed sidnei-polo closed 1 year ago
Thanks for the report @sidnei-polo Per documentation:
There are a few preconditions which must be met before the application can receive message payloads via FCM:
The application must have opened at least once (to allow for registration with FCM).
On iOS, if the user swipes away the application from the app switcher, it must be manually reopened for background messages to start working again.
So, if your app is terminated, can you manually reopen and then check if you still get it as null
?
Also, In the plugin example, the keyword is `https://github.com/firebase/flutterfire/blob/f36785770a6d2c3de981d5bd339166a22af617f4/packages/firebase_messaging/firebase_messaging/example/scripts/send-message.js#L32
Whereas, you have it as content-available
. Can you try with contentAvailable
and see if it helps ?
Thanks for the reply @darshankawar.
I'm using the FCM V1 API to send the notification, and according to the documentation, I have to send the platform-specific payload following the documentation from the platform. In this case content-available
. But, it is also reproducible using the legacy API with the "content_available": true
key.
I also understand for content-available
to work, the app must not be terminated with the user swipe action, and if the app is in the background, it will use the FirebaseMessaging.onBackgroundMessage
callback. That is working fine with the "content-available":1
. But, if the app is indeed terminated with the user swipe action when the user taps on a notification that opens the app, the getInitialMessage
should return that notification, even if the notification contains content-available
, right?
And from my tests, it does return the tapped notification, but only if I add a delay before calling getInitialMessage
on the app startup.
Thanks for the feedback. Using the code sample provided, seeing the same behavior as reported.
/cc @russellwheatley
@sidnei-polo I used your code sample. I also used the Node.js Firebase admin library to send the requests. I received the initial message 100% of the time after pressing the notification from a terminated state. I tried roughly ten times. Here is the code I used to send:
admin
.messaging()
.sendToDevice(
[iosToken],
{
data: {
some: 'data',
},
notification: {
title: 'A great title',
body: 'Great content',
},
},
{
contentAvailable: true,
priority: 'high',
}
)
If it works for me, then I can only presume there is something wrong with the way it is handled using the REST API or perhaps something wrong with the way the shape of the request being sent. Could you try using the Firebase admin SDK and let me know if it works for you?
Hey @sidnei-polo. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
Hey @russellwheatley, I didn't have the opportunity to use the Node.js SDK yet. But this is also happening when we use Firebase Admin Python SDK, so I guess it is most probably an issue on the app side when handling the income message.
Payload used with python SDK:
{
"validate_only":false,
"message":{
"notification":{
"title":"title",
"body":"message"
},
"token":"fcm_token",
"data":{
"click_action":"FLUTTER_NOTIFICATION_CLICK"
},
"apns":{
"payload":{
"aps":{
"content-available":1
}
}
}
}
}
Any update on this?
Facing similar issue, with Firebase Admin Python SDK.
Payload used with python SDK:
How did you manage to fix the bug?
{
"aps" : {
"content-available" : 1
},
}
I'd encourage you all to use the example Nodejs admin script that we have setup here: https://github.com/firebase/flutterfire/blob/91d8aa72f627620245fe15df48f2d68f204e3d10/packages/firebase_messaging/firebase_messaging/example/scripts/send-message.js
Let me know if that works.
Let me know if that works.
I use this package for send notifications from backend
Like this not working for me
"contentAvailable": true
But like this work perfectly
"content-available" : 1
Closing out, this is not an issue. Please use nodejs admin SDK script to send notifications if you're struggling to receive messages. See example script here
Bug report
Describe the bug On iOS, when sending a notification with the
content_available
key, thegetInitialMessage
method is returning null. Adding a delay before callinggetInitialMessage
seems to solve the problem, but it is not ideal.Steps to reproduce
Steps to reproduce the behavior:
Expected behavior
getInitialMessage
should wait and return the notification even when the notification contains thecontent_available
key.Sample project
Here's a simple project where the issue is reproducible. It obtains the FCM token and displays the initial message when starting the app. If the app gets started from a notification tap on a notification that contains
content_available:1
, it does not display the initial message as thegetInitialMessage
returns null.Additional context
It looks like the
getInitialMessage
is not waiting for the notification to be processed when the app starts. If a delay before callinggetInitialMessage
is added, it returns the notification properly.Flutter doctor
Run
flutter doctor
and paste the output below:Click To Expand
``` Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.3.10, on macOS 12.6.1 21G217 darwin-arm, locale en-DE) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1) [✓] Xcode - develop for iOS and macOS (Xcode 14.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.3) [✓] VS Code (version 1.75.0) [✓] Connected device (3 available) [✓] HTTP Host Availability • No issues found! ```Flutter dependencies
Run
flutter pub deps -- --style=compact
and paste the output below:Click To Expand
``` Dart SDK 2.18.6 Flutter SDK 3.3.10 messaging_test 1.0.0+1 dependencies: - cupertino_icons 1.0.5 - firebase_core 2.9.0 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_messaging 14.4.0 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine] dev dependencies: - flutter_lints 2.0.1 [lints] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters collection matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph] transitive dependencies: - _flutterfire_internals 1.1.0 [collection firebase_core firebase_core_platform_interface flutter meta] - async 2.9.0 [collection meta] - boolean_selector 2.1.0 [source_span string_scanner] - characters 1.2.1 - clock 1.1.1 - collection 1.16.0 - fake_async 1.3.1 [clock collection] - firebase_core_platform_interface 4.6.0 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.3.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_messaging_platform_interface 4.3.0 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 3.3.0 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math] - js 0.6.4 - lints 2.0.1 - matcher 0.12.12 [stack_trace] - material_color_utilities 0.1.5 - meta 1.8.0 - path 1.8.2 - plugin_platform_interface 2.1.4 [meta] - sky_engine 0.0.99 - source_span 1.9.0 [collection path term_glyph] - stack_trace 1.10.0 [path] - stream_channel 2.1.0 [async] - string_scanner 1.1.1 [source_span] - term_glyph 1.2.1 - test_api 0.4.12 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher] - vector_math 2.1.2 ```