-
Notifications
You must be signed in to change notification settings - Fork 173
change badge count in background #58
Comments
+1 |
@g123k please check this |
Which library are u using for push notification? if you are working with firebase_messaging u can use backgoundHandler It's working for me. Future<void> _backgroundNotificationHandler(RemoteMessage message) async {
final preferences = await SharedPreferences.getInstance();
const key = '@badge_count';
// Get Last Badge Count
final count = (preferences.getInt(key) ?? 0) + 1;
// Update Badge Count
await preferences.setInt(key, count);
Native.badgeUpdate(count);
} |
Hello @GeceGibi , What is "Native" ? My code looks like this : Future<void> main() async {
FirebaseMessaging.onBackgroundMessage(handleBackgroundMessage);
runApp(child: const MyApp()));
}
Future<void> handleBackgroundMessage(RemoteMessage remoteMessage) async {
FlutterAppBadger.updateBadgeCount(1);
} |
Ups sorry my bad. |
Ok anyway the problem for me is same as #57 |
If background handler not working. U should add
in your plist file. |
It does only work when you click on the notification? Isn't it? |
Nope. It's working when app in background. |
Hey, so while this is working for me using the onMessage function while the app is in the foreground, it does not seem to be working for me in the backroundHandler. Am I doing something wrong? The notification that I am sending has both a notification component and a data component; would that affect the performance in some way? I am not even sure if my backgroundHandler is being triggerred although it is properly configured. I can see the notifications received in background however. |
@GeceGibi Following your instructions I was able to make it work while app was in background i.e not terminated and is only minimized and app is in foreground. But This doesn't seems to be working while app is terminated or removed from recent app list in iOS. BTW i am able to receive the notification even if the app is terminated however I am not able to update the badge count. Below is the snippet of how my background handler looks like. Thanks 🙏
|
It's obvious that it will not work when the app is terminated. As mentioned in the docs here.
|
@GeceGibi Thanks for the response. I have managed to get it working even if the app is terminated. 🍻 |
The following code works perfectly for me. It also stores badge count locally so you don't need to store it anywhere in cloud database. Future firebaseMessagingBackgroundHandler(RemoteMessage message) async { // Get Last Badge Count // Update Badge Count FlutterAppBadger.updateBadgeCount(count); print(message.data); // await Firebase.initializeApp(); |
Please share your knowledge So others can learn. |
did anyone solve the issue? |
|
You mean content available property? |
Yes, if the issue is iOS specific that might be the problem as I fixed with that |
Hello, we are having issue the Android app badge would not reset. Can someone provide any advice and help? I really appreciate any advice and insights you could offer. |
this is not working for me. Is there any other settings for ios device. btw if I open my app and send notification from firebase, counter is working. but while app is closed counter is not working. I can take notification but I cant change the count |
+1 same, my onBackgroundMessage (background) also not working. |
Hi mister. If you are using the firebase push notification, you can send badge count from the firebase push notification service. It is working automatically. I solved this issue just like that. You can check the firabse push notification docs. It would be helpful |
how to change badge count when app is in background. for example, when i receive push notification, i have to increase the badge count
The text was updated successfully, but these errors were encountered: