【问题标题】:FCM handles IOS notification when app is foreground which is I do not want to当应用程序处于前台时,FCM 处理 IOS 通知,这是我不想
【发布时间】:2021-10-17 09:21:52
【问题描述】:

我在我的 Flutter 项目中使用 fcm 和 local_notifications 来处理推送通知。

使用此有效负载发送通知:

{
  token: body.token,
  notification = {
      title: body.data.title,
      body: body.data.body,
  },
  data: {
      data: JSON.stringify(body.data),
  }
}

所以当通知到来时

应用终止:两个应用(ios - android)的通知都完美显示

在应用背景上:两个应用(ios - android)的通知都完美显示

在应用前台:

android 应用程序: 通知就像数据通知一样,fcm 不会像我想要的那样提醒任何东西。

ios 应用程序: 当通知到来时,fcm 会显示一个我不想显示的警报。同时 local_notifications 也在显示。

我的问题是 fcm 处理 ios 应用程序上的前台通知。当它以这种方式工作时,我无法禁用不应出现在前台的通知。

pubspec.yaml:

firebase_messaging: ^10.0.4
flutter_local_notifications: ^8.1.1+1

firebase 前台通知选项:

await instance.setForegroundNotificationPresentationOptions(alert: true, badge: true, sound: true);

当我删除 firebase 前台通知选项或将所有参数设置为 false 时,local_notifications 也无法显示任何通知。

local_notifications 前台通知选项:

instance.resolvePlatformSpecificImplementation<IOSFlutterLocalNotificationsPlugin>()?.requestPermissions(
          alert: true,
          badge: true,
          sound: true,
        );

谢谢。

【问题讨论】:

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


    【解决方案1】:

    我找到了解决方案: 太明显了:D

    await instance.setForegroundNotificationPresentationOptions(alert: false, badge: true, sound: true);
    

    如果您不希望 FCM 处理前台警报,则警报参数应为 false。

    【讨论】:

      猜你喜欢
      • 2018-07-31
      • 2018-09-07
      • 2021-04-19
      • 2020-05-17
      • 2022-01-01
      • 2016-11-21
      • 2019-01-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多