| .. | .. |
|---|
| 8 | 8 | _ application: UIApplication, |
|---|
| 9 | 9 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? |
|---|
| 10 | 10 | ) -> Bool { |
|---|
| 11 | | - application.applicationIconBadgeNumber = 0 |
|---|
| 12 | | - if #available(iOS 16.0, *) { UNUserNotificationCenter.current().setBadgeCount(0) } |
|---|
| 13 | 11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions) |
|---|
| 14 | 12 | } |
|---|
| 15 | 13 | |
|---|
| .. | .. |
|---|
| 17 | 15 | GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry) |
|---|
| 18 | 16 | } |
|---|
| 19 | 17 | |
|---|
| 20 | | - // Clear badge when app becomes active |
|---|
| 21 | | - override func applicationDidBecomeActive(_ application: UIApplication) { |
|---|
| 22 | | - super.applicationDidBecomeActive(application) |
|---|
| 23 | | - application.applicationIconBadgeNumber = 0 |
|---|
| 24 | | - if #available(iOS 16.0, *) { UNUserNotificationCenter.current().setBadgeCount(0) } |
|---|
| 18 | + // Read badge count from Flutter's SharedPreferences (UserDefaults) and update icon |
|---|
| 19 | + private func updateBadgeFromPrefs() { |
|---|
| 20 | + // Flutter SharedPreferences stores ints with "flutter." prefix |
|---|
| 21 | + let prefs = UserDefaults.standard |
|---|
| 22 | + let count = prefs.integer(forKey: "flutter.badgeCount") |
|---|
| 23 | + UIApplication.shared.applicationIconBadgeNumber = count |
|---|
| 25 | 24 | } |
|---|
| 26 | 25 | |
|---|
| 26 | + // Don't touch badge on resume — APNs sets it, Flutter decrements it on session view |
|---|
| 27 | + |
|---|
| 28 | + // Badge handled by Flutter via platform channel on session switch and background |
|---|
| 29 | + |
|---|
| 27 | 30 | // Forward APNs token registration to the push plugin |
|---|
| 28 | 31 | override func application( |
|---|
| 29 | 32 | _ application: UIApplication, |
|---|