【问题标题】:Flutter FirebaseMessaging notification is removed automatically when the app goes in foreground当应用程序进入前台时,Flutter FirebaseMessaging 通知会自动删除
【发布时间】:2020-01-06 22:43:24
【问题描述】:

当我点击应用程序(不是通知)时,每个通知都会自动删除。 这是一个大问题,当用户打开应用程序并删除所有通知时

【问题讨论】:

  • 我使用了 Firebase 消息传递 5.14 和颤振 1.74。我在ios 9和ios 12中测试的问题。问题是一样的

标签: firebase flutter push-notification firebase-cloud-messaging


【解决方案1】:

当应用程序进入前台时,我发现了一个不需要的自动清理通知场景。它位于第 159 行 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;
}

这似乎是徽章计数器的一种解决方法。我还开了一个issue:https://github.com/FirebaseExtended/flutterfire/issues/114

【讨论】:

  • 我面临这个问题如何找到这个文件来删除这些行? @JasperShih
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-17
  • 1970-01-01
相关资源
最近更新 更多