flutterfire
flutterfire copied to clipboard
🐛 [firebase_messaging] Why ios badge data is managed in alert ?
Bug report
Describe the bug
When my spring server send FCM push message by using firebase admin client to my flutter app, firebase_messaging package handles ios payload uncorrectly. below is fcm ios payload
aps = {
alert = {
body = "!@#!@#";
title = Test;
};
badge = 3;
"content-available" = 1;
};
I found that this package extract badge data from apsAlertDict not from apsDict. is it right?
obviously in flutter project, badge data in remoteMessage is null because apsAlertDict have not badge.
I don't understand and i can't find any who ask this problem.
@bebe0612 What's the expected result are you looking for when you send that payload ?
@darshankawar you know, badge is notification count exposed on app home icon in ios. also, RemoteMessage class it represents firebase push message have badge property.
When I send fcm message with badge, We should be able to get badge count in message.notification.apple.badge in flutter side.
but this package get badge data in aps.alert.badge not aps.badge so this is problem what i claim.
is it my fault ?
Check this comment and see if it helps.
@darshankawar thank you for answer. but still i can't understand why the pacakge parse ios payload uncorrectly. the badge data is in aps dict not apsAlert dict. is there a reason? I send fcm message by using java spring firebase admin.
Thanks for the feedback.
I see that the badge is being extracted from apsAlertDict as:
notificationIOS[@"badge"] = apsAlertDict[@"badge"];
https://github.com/firebase/flutterfire/blob/49921a4362c5965d2efeed17eb73775302007ea8/packages/firebase_messaging/firebase_messaging/ios/Classes/FLTFirebaseMessagingPlugin.m#L939
Looking at apsAlert documentation: https://firebase.google.com/docs/reference/admin/dotnet/class/firebase-admin/messaging/aps-alert, it doesn't seem to have badge property, unlike aps which has it:
https://firebase.google.com/docs/reference/admin/dotnet/class/firebase-admin/messaging/aps#badge
I am not exactly sure if this is expected behavior, so keeping this issue open for further insights from the team.
/cc @russellwheatley
@darshankawar @russellwheatley Is there any update on this? Seeing the same issue.
@allen-impact
In flutter, I think, managing badge data in fcm is not a good way because it only handles each native side.
Instead, It is a good way to handle on the flutter side by using flutter_app_badger package.
If you do this, you can handle not only fcm badge data but custom badge data also.
In my case, I have to handle badge count in background, but thanks to fcm background handler function and shared_preference, I can handle that when application is terminated or background.
Maybe many developer are knowing this trick that no one raise this issue.
@bebe0612 Thanks for your reply!
Yeah, I am using that package now to update the badge count, but it's still unfortunate that fcm is not able to correctly parse the Apple payload for badge count. Seems like a bug in the framework given it always returns null when it should not.
Thanks for the report. Confirmed and PR is here.
@allen-impact
In flutter, I think, managing badge data in fcm is not a good way because it only handles each native side.
Instead, It is a good way to handle on the flutter side by using flutter_app_badger package.
If you do this, you can handle not only fcm badge data but custom badge data also.
In my case, I have to handle badge count in background, but thanks to
fcm background handler functionandshared_preference, I can handle that when application is terminated or background.Maybe many developer are knowing this trick that no one raise this issue.
My firebase background handler does not get triggered on IOS when app is terminated or in background, so, I can't update the badge count. Any solutions?