how to remove notification badge -Flutter

Viewed 635

I have flutter app and I use push notification in it

When I receive new notification I remove all notification and badge but sometimes notification badge not remove when open app and it keep increasing

Here is solution I found to remove badge:-

Ios->appDelegete.swift

import UIKit
import Flutter
import Firebase
import UserNotifications

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    FirebaseApp.configure()
    GeneratedPluginRegistrant.register(with: self)

      if #available(iOS 10.0, *) {
                application.applicationIconBadgeNumber = 0 // For Clear Badge Counts
               let center = UNUserNotificationCenter.current()
               center.removeAllDeliveredNotifications()
                center.removeAllPendingNotificationRequests()
                center.delegate = self  as? UNUserNotificationCenterDelegate
            }

       return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

But it don't remove my badge is there any way to remove notification badge?

1 Answers

Try to Add Below Code In side you AppDelegate.swift after didFinishLaunchingWithOptions

override func applicationDidEnterBackground(_ application: UIApplication){
   application.applicationIconBadgeNumber = 0
}

Hope it's work for you

Related