Flutter Firebase Messaging触发启动 [英] Flutter Firebase Messaging trigger onLaunch

查看:39
本文介绍了Flutter Firebase Messaging触发启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个问题,因为我不完全了解某些内容.因此,我编写了一个简单的应用程序来尝试一些操作,因此我通过Firebase Cloud Messaging从Firebase发送了一条消息.我使用firebase_messaging flutter插件(7.0.3版).获取消息并导航到另一页面只是一件简单的事情.我的问题是以下问题,onMessage和onResume函数可以正常工作,但是当应用终止时,我单击通知打开了应用,但没有任何反应.所以我阅读了文档,发现了这个第三行说数据丢失了……这是否意味着我丢失了有效载荷中的所有数据?如果有帮助,我的代码就在这里

So I have a question, because I am not fully understand something. So I wrote a simple app, to try something, so I send a message from Firebase via Firebase Cloud Messaging. I use the firebase_messaging flutter plugin (7.0.3 version). It just does a simple thing to get the message and navigate to another page. My problem is the following one, the onMessage and the onResume function works perfectly, but when the app is terminated and I click on the notification the app opens but nothing happens. So I read the documentation and I found this The third row says, that the data is lost... Does this mean that I lost every data in the payload? My code is here if it helps

 static final NavigationService _navigationService =
      loc.Locator.locator<NavigationService>();
  final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();

  Future<void> reqPermission() async {
    bool permission = true;
    if (Platform.isIOS) {
      permission = await _firebaseMessaging.requestNotificationPermissions();
    }
    if (permission) {
      _firebaseMessaging.configure(
        onMessage: (Map<String, dynamic> message) async {
          print(message);
          await _navigationService.navigateTo(NewPage.routeName);
        },
        onLaunch: (Map<String, dynamic> message) async {
          print('onLaunch $message');
          await _navigationService.navigateTo(NewPage.routeName);
        },
        onResume: (Map<String, dynamic> message) async {
          print('onResume $message');
          await _navigationService.navigateTo(NewPage.routeName);
        },
        onBackgroundMessage: _myBackgroundHandler,
      );
    }
  }

推荐答案

我最近在GitHub上问了这个问题,请参见:

I recently asked this question on GitHub, see: https://github.com/FirebaseExtended/flutterfire/issues/5098#issuecomment-783444919

这对于旧版本是正确的,它需要一个本机解决方法.最新的非null安全版本firebase_messaging:^ 8.0.0-dev.14将在终止状态下工作(除非您在Android上强制退出该应用程序).更新的文档位于 https://firebase.flutter.dev/docs/messaging/usage#receiving-messages

这篇关于Flutter Firebase Messaging触发启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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