Description
Describe the bug
After sending a notification via google-api-php-client to GCM, I receive the same message twice on a device: both onMessage and onLaunch are triggered with the same gcm.message_id.
To Reproduce
Steps to reproduce the behavior:
- Send message to an individual iPhone 11 device (with its token or using a topic) via google-api-php-client:
["message"]=>
array(6) {
["token"]=>
string(152) "<TOKEN>"
["notification"]=>
array(2) {
["title"]=>
string(12) "<TITLE>"
["body"]=>
string(48) "<BODY>"
}
["data"]=>
array(5) {
["category"]=>
string(7) "<CATEGORY>"
["type"]=>
string(16) "<TYPE>"
["title"]=>
string(33) "<TITLE>"
["url"]=>
string(62) "<URL>"
["id"]=>
string(4) "<ID>"
}
["apns"]=>
array(1) {
["payload"]=>
array(1) {
["aps"]=>
array(2) {
["sound"]=>
string(7) "default"
["content-available"]=>
int(1)
}
}
}
["android"]=>
array(2) {
["priority"]=>
string(4) "HIGH"
["notification"]=>
array(2) {
["click_action"]=>
string(26) "FLUTTER_NOTIFICATION_CLICK"
["sound"]=>
string(7) "default"
}
}
["fcm_options"]=>
array(1) {
["analytics_label"]=>
string(16) "<LABEL>"
}
}
- With my app closed, when I tap on the notification in iOS, the same message is handled by the device twice. Here's what's comes in the log in Console:
onMessage
flutter: FCM: onMessage: {category: <CATEGORY>, google.c.a.e: 1, id: <ID>, aps: {alert: {title: <TITLE>, body: <BODY>}, sound: default, content-available: 1.0}, title: <TITLE>, type: <TYPE>, google.c.a.m_l: <CATEGORY>, gcm.message_id: 1580433692277472, url: <URL>}
onLaunch
flutter: FCM: onLaunch: {category: <CATEGORY>, google.c.a.e: 1, id: <ID>, aps: {alert: {title: <TITLE>, body: <BODY>}, sound: default, content-available: 1.0}, title: <TITLE>, type: <TYPE>, google.c.a.m_l: <CATEGORY>, gcm.message_id: 1580433692277472, url: <URL>}
Expected behavior
With the app closed, I'd expect to see onLaunch processed by the app, and not onMessage.
Additional context
I'm using firebase_core ^0.4.3+1, firebase_messaging ^6.0.9, and firebase_analytics ^5.0.9 in my app at the moment.
I haven't been able to reproduce this issue in the iOS Simulator, Android simulator, or on an Android device. I haven't been able to reproduce this on several other iOS devices I have access to, either. Unsubscribing from notifications (via unsubscribeFromTopic()
), reinstalling the app, and then resubscribing didn't make a difference.
Not sure if it matters, but the two devices I can replicate this on were both recently upgraded and migrated from older iPhones.
Here's the code snippets I use to handle the notifications:
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> m) async {
debugPrint('FCM: onMessage: $m');
m['messageType'] = 'onMessage';
_handleFCMMessage(m);
},
onLaunch: (Map<String, dynamic> m) async {
debugPrint('FCM: onLaunch: $m');
m['messageType'] = 'onLaunch';
_handleFCMMessage(m);
},
onResume: (Map<String, dynamic> m) async {
debugPrint('FCM: onResume: $m');
m['messageType'] = 'onResume';
_handleFCMMessage(m);
},
);
Activity
iapicca commentedon Feb 3, 2020
Hi @RabbitKabong
I see there's an open issue addressing the case you described.
Please follow up on that issue,
I'm closing the current one as duplicate.
If you disagree please write in the comments
and I will reopen it.
Thank you
RabbitKabong commentedon Feb 3, 2020
Yeah, when I did some initial investigation I saw #1669, too, but 2 things stick out to me:
message_id
s when the duplicates come in. I'm seeing the same message_id.I think this is a separate issue.
red42 commentedon Mar 30, 2020
It looks like the culprit is:
Which gets called both when the app is in background (when we want to call "onResume") and when the app is not running at all.
Checking if there's no _launchNotification pending seems to be enough to avoid the problem.
I'm adding a PR with the change.
[firebase_messaging] Fix both onMessage and onLaunch being called on iOS
[firebase_auth] Update auth methods to return AuthResult instead of F…
Salakar commentedon Apr 16, 2021
Closing in favour of trying the latest messaging version which has since this issue was created been heavily reworked to improve it along with detailed documentation: https://firebase.flutter.dev/docs/messaging/overview
If you still have a problem please raise a new GitHub issue with up to date information and code snippets if possible. Thanks.