Skip to content

[firebase_messaging] undesired auto cleaning notifications when entering foreground (iOS) #114

@JasperShih

Description

@JasperShih

Describe the bug
Hi, I found a undesired auto cleaning notifications scenario when application entering foreground. It is at line 159 in
https://github.com/FirebaseExtended/flutterfire/blob/master/packages/firebase_messaging/ios/Classes/FirebaseMessagingPlugin.m

- (void)applicationDidBecomeActive:(UIApplication *)application {
  _resumingFromBackground = NO;
  // Clears push notifications from the notification center, with the
  // side effect of resetting the badge count. We need to clear notifications
  // because otherwise the user could tap notifications in the notification
  // center while the app is in the foreground, and we wouldn't be able to
  // distinguish that case from the case where a message came in and the
  // user dismissed the notification center without tapping anything.
  // TODO(goderbauer): Revisit this behavior once we provide an API for managing
  // the badge number, or if we add support for running Dart in the background.
  // Setting badgeNumber to 0 is a no-op (= notifications will not be cleared)
  // if it is already 0,
  // therefore the next line is setting it to 1 first before clearing it again
  // to remove all
  // notifications.
  application.applicationIconBadgeNumber = 1;
  application.applicationIconBadgeNumber = 0;
}

To Reproduce

  1. get >=2 remote notifications on iPhone
  2. enter foreground
  3. all notifications & badges be unexpectedly removed

Expected behavior
Just remove the notification we clicked. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions