Comments (8)
hmmmm, after investigating for some time, I don't think there is anything we can do about this. The problem is; we receive the RemoteMessage here, but when the user taps the notification, we receive the intent here.
The intent contains the following in the extras:
{
notificationId: 123456,
payload: ""
}
This does not allow us to tie the message received with the notification tapped (notificationId
is not a property on the RemoteMessage
when the message is received). This is different to when the message is received in the background. Here is the documentation
The data is not contained within the intent itself when the message is received in the foreground. Therefore, we have no way of knowing what the initial message is.
Your best bet might be to use data-only messages and handle the notifications yourself rather than use firebase messaging to handle the notifications.
from flutterfire.
@cogivn - I mean you might consider using data-only messages to trigger a notification using another Flutter plugin (such as flutter_local_notifications). Presumably they don't have the same limitation on android when the message is received in the foreground.
from flutterfire.
Hi @cogivn ,
Thank you for your submission and for taking the time to provide detailed information about the issue. We will look into it and get back to you
from flutterfire.
I wasn't able to reproduce. Here is how you can test:
- Run app in release i.e.
flutter run --release
. - Terminate app (it will still be running when in release mode).
- Send message (I use nodjs admin SDK. See here)
- Open app via notification and print out the message returned from
getInitialMessage()
.
So I had a print here in firebase_messaging example app:
FirebaseMessaging.instance.getInitialMessage().then(
(value) => setState(
() {
print('${value?.data.toString()}');
_resolved = true;
initialMessage = value?.data.toString();
},
),
);
and here are the logs from console:
Flutter run key commands.
h List all available interactive commands.
c Clear the screen
q Quit (terminate the application on the device).
I/flutter (21076): Handling a background message 0:1718036389166773%50d7604150d76041
I/flutter (21076): {foo: bar, float: 12034}
I/flutter (21076): FCM Token: dEUSTNftSGmTqpr2TeKx
I sent this in my nodejs admin script:
admin
.messaging()
.send(
{
token: androidToken,
data: {
foo: 'bar',
float: '12034'
},
notification: {
title: 'A great title',
body: 'Great content',
},
android: {
// Required for background/terminated app state messages on Android
priority: 'high',
},
apns: {
payload: {
aps: {
// Required for background/terminated app state messages on iOS
contentAvailable: true,
},
},
},
},
)
you can see the data is:
data: {
foo: 'bar',
float: '12034'
},
from flutterfire.
I wasn't able to reproduce. Here is how you can test:
- Run app in release i.e.
flutter run --release
.- Terminate app (it will still be running when in release mode).
- Send message (I use nodjs admin SDK. See here)
- Open app via notification and print out the message returned from
getInitialMessage()
.So I had a print here in firebase_messaging example app:
FirebaseMessaging.instance.getInitialMessage().then( (value) => setState( () { print('${value?.data.toString()}'); _resolved = true; initialMessage = value?.data.toString(); }, ), );and here are the logs from console:
Flutter run key commands. h List all available interactive commands. c Clear the screen q Quit (terminate the application on the device). I/flutter (21076): Handling a background message 0:1718036389166773%50d7604150d76041 I/flutter (21076): {foo: bar, float: 12034} I/flutter (21076): FCM Token: dEUSTNftSGmTqpr2TeKxI sent this in my nodejs admin script:
admin .messaging() .send( { token: androidToken, data: { foo: 'bar', float: '12034' }, notification: { title: 'A great title', body: 'Great content', }, android: { // Required for background/terminated app state messages on Android priority: 'high', }, apns: { payload: { aps: { // Required for background/terminated app state messages on iOS contentAvailable: true, }, }, }, }, )you can see the data is:
data: { foo: 'bar', float: '12034' },
Hi @russellwheatley,
please swap the step 2 and 3 like this:
- Send message when app in foreground(displayed the notification but do not tap into notification)
- Kill app (Terminate app)
- Tap into notification to launch the app again.
from flutterfire.
I get the same bug, FirebaseMessaging.instance.getInitialMessage() return null.
Reprodeced only on ios (test on 16.7.8)
If I send 2 notification, and click one of them it's work for first and second notification.
Maybe in documentation lost some information about AppDelegete.swift to configure or smt else ?
from flutterfire.
Hey @cogivn - I was able to reproduce, I'll see what can be done to fix this issue 👍
from flutterfire.
Hi @russellwheatley,
Would be grateful if you could elaborate on the use of data-only messages as a potential solution to this issue. While I understand that notification handling for both notification messages
and data-only messages
is likely required when app is in foreground on the Android platform, the problem appears to persist even when a user taps on a notification after the application has been terminated.
from flutterfire.
Related Issues (20)
- [firebase_crashlytics]: flutter macOS does not terminate the app after stop debuging HOT 6
- Found some security issues HOT 3
- [firebase_auth] linkWithCredential() throws email-already-in-use exception in flutter app
- Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform, ) intialize issue HOT 1
- [firebase_auth] authStateChanges() stream fires when read/write into firestore HOT 4
- 🐛 [firebase_massaging] Example flutter ios build is too old
- firebase_code: Duplicate Classes HOT 6
- Firebase Phone MFA not working with some numbers HOT 1
- [📚] Old Doc doesn't have sum() and average() example for flutter. HOT 1
- [Firebase storage]: iOS only - Unable to establish connection to channel, happens in Workmanager or isolate only HOT 1
- [Firebase_auth]: <When I use signInWithEmailAndPassword without first using the createUserWithEmailAndPassword method, I get the error message [firebase_auth/channel-error] "dev.flutter.pigeon.firebase_auth_platform_interface.FirebaseAuthHostApi.signInWithEmailAndPassword".> HOT 11
- 🐛 [crashlytics][release] Information from recordFlutterFatalError shows up as 'Instance of 'DiagnosticsProperty<void>'
- [firebase_app_check] App check token does not print on Android real devices HOT 6
- [firebase_auth]: [web] referencing FirebaseAuthException after running release version of app throws exception. HOT 2
- [firebase_messaging]: After turning off the device and turn back on, onBackgroundMessage is not fired on iOS. HOT 1
- [firebase_messaging]: After turning off the device and turn back on, onBackgroundMessage is not fired on iOS. HOT 3
- [firebase_core]: Cannot build app from version 3.0.0 HOT 2
- [FirebaseAuth]: Unhandled Exception: type 'List<Object?>' is not a subtype of type 'PigeonUserInfo' in type cast HOT 3
- [firebase_analytics]: `TypeError: Cannot convert undefined or null to object` when hot reload web application HOT 2
- [📚] README files in `example` directories have outdated docs and links
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutterfire.