【问题标题】:How to show a push-notification when the application is open(foreground), when OnMessage is triggered?如何在应用程序打开(前台)、触发 OnMessage 时显示推送通知?
【发布时间】:2020-07-10 01:27:44
【问题描述】:

我使用 Flutter 和 Firebase 消息传递。 我在示例中配置 Firebase:
firebaseMessaging.configure( onMessage: ... onLaunch: ... onResume: ... )
但即使应用程序打开,我也想看到推送通知。
粗略地说 onMessage 应该像 onResume 一样工作。
我该怎么做?

【问题讨论】:

    标签: firebase flutter firebase-cloud-messaging


    【解决方案1】:
      onMessage: (Map<String, dynamic> message) async {
            showNotification(message);
            print('on message $message');
          }
    
    
    
    
      showNotification(Map<String, dynamic> msg) async {
        var android = new AndroidNotificationDetails(
          'your channel id',//channel id
          "your channel name",//channel name
          "your channel description",//channel desc todo set all this right
          icon: 'mipmap/launcher_icon'//add your icon here
        );
        var iOS = new IOSNotificationDetails();
        var platform = new NotificationDetails(android, iOS);
    
    
        await flutterLocalNotificationsPlugin
            .show(0, msg['notification']['title'], msg['notification']['body'], platform);
    
    
      }
    
    

    我使用flutter_local_notifications: ^1.2.2 显示本地通知前台。

    此外,如果您正在为 IOS 实施,请不要忘记请求通知权限。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-25
      • 1970-01-01
      • 2020-01-09
      • 2021-06-30
      相关资源
      最近更新 更多