Flutter:Foreground通知在Firebase消息传递中不起作用 [英] Flutter: Foreground notification is not working in firebase messaging

查看:168
本文介绍了Flutter:Foreground通知在Firebase消息传递中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过使用本地通知在应用程序处于前台时显示Firebase通知,但无法正常工作。

I need to show firebase notifications when the app is on foreground by using local notification but it is not working.

  FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin=new FlutterLocalNotificationsPlugin();

  static  FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
  static StreamController<Map<String, dynamic>> _onMessageStreamController =
  StreamController.broadcast();
  static StreamController<Map<String, dynamic>> _streamController =
  StreamController.broadcast();
  static final Stream<Map<String, dynamic>> onFcmMessage =
      _streamController.stream;

  @override
  void initState() {
    super.initState();

    var android=AndroidInitializationSettings('mipmap/ic_launcher.png');
    var ios=IOSInitializationSettings();
    var platform=new  InitializationSettings(android,ios);
    flutterLocalNotificationsPlugin.initialize(platform);

    firebaseCloudMessaging_Listeners();
  }

这是Firebase代码

Here is the Firebase Code

 void firebaseCloudMessaging_Listeners() {

if (Platform.isIOS) iOS_Permission();

_firebaseMessaging.getToken().then((token) {
  print("FCM TOKEN--" + token);
});
_firebaseMessaging.configure(
  onMessage: (Map<String, dynamic> message) async {
    print('on message $message');
    showNotification(message);
  },
  onResume: (Map<String, dynamic> message) async {
    print('on resume $message');
  },
  onLaunch: (Map<String, dynamic> message) async {
    print('on launch $message');
  },
);


}

这是 showNotification 方法

 void showNotification(Map<String, dynamic> msg) async{
    print(msg);
    var android = new AndroidNotificationDetails(
        'my_package', 'my_organization', 'notification_channel', importance: Importance.Max, priority: Priority.High);
    var iOS = new IOSNotificationDetails();
    var platform=new NotificationDetails(android, iOS);
    await flutterLocalNotificationsPlugin.show(
      0,'My title', 'This is my custom Notification', platform,);
  }

和Firebase响应

and Firebase Response

{通知:{标题:测试标题,正文:测试通知文本},数据:{orderid:2,click_action:FLUTTER_NOTIFICATION_CLICK,订单名称:farhana}}

{notification: {title: Test Title, body: Test Notification Text}, data: {orderid: 2, click_action: FLUTTER_NOTIFICATION_CLICK, order name: farhana}}


推荐答案

在GitHub存储库上记录了与此软件包相关的活跃问题。 Firebase消息传递和本地通知在iOS上无法一起使用,因为您只能为通知注册一个委托。

There is an active issue logged on GitHub repository for the package regarding the same. Firebase messaging and local notifications won't work together on iOS since you can register only a single delegate for notifications.

签出: https://github.com/MaikuB/flutter_local_notifications/issues/111

同样存在一个活跃的抖动问题:
https:// github .com / flutter / flutter / issues / 22099

There's also an active flutter issue for the same: https://github.com/flutter/flutter/issues/22099

这篇关于Flutter:Foreground通知在Firebase消息传递中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆