Firebase_messaging onResume和onLaunch回调未在flutter中调用

问题描述 投票:0回答:1

我想做什么

当用户在通知托盘中点击fcm通知时,我想导航到特定屏幕。

我的代码

我已遵循与pub.dev版本6.0.9完全相同的说明。

这是我的实现:

_fcm.configure(
        onMessage: (Map<String, dynamic> message) async {
          print('@onMessage: $message');
        },
        onResume: (Map<String, dynamic> message) async {
          print('@onResume: $message');
          Navigator.push(context,
              MaterialPageRoute(builder: (context) => NotificationsScreen()));
        },
        onLaunch: (Map<String, dynamic> message) async {
          print('@onLaunch: $message');
          Navigator.push(context,
              MaterialPageRoute(builder: (context) => NotificationsScreen()));
        });

插件版本: firebase_messaging:^ 6.0.9

我还添加了以下配置:

app / build.gradle:

implementation 'com.google.firebase:firebase-messaging:20.1.0'

project / build.gradle:

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:'1.3.50'"
classpath 'com.google.gms:google-services:4.3.3'

预期输出

[当用户在背景中点击通知时,将调用onResume或onLaunch回调并将其重定向到上述屏幕。

实际输出

onResume和onLaunch在应用程序处于前台时正确调用onMessage时未调用。

flutter callback firebase-cloud-messaging
1个回答
0
投票

如果通知有效负载缺少“ click_action”:“ FLUTTER_NOTIFICATION_CLICK”,则onclick和onresume函数不会被调用,但是onmessage函数会完美运行。在终端中尝试此有效负载

DATA='{"notification": {"body": "this is a body","title": "this is a title"}, "priority": "high", "data": {"click_action": "FLUTTER_NOTIFICATION_CLICK",  "route":"booking", "bookingId":"319", "userType":"host", "status": "done"}, "to": "<FCM TOKEN>"}'
curl https://fcm.googleapis.com/fcm/send -H "Content-Type:application/json" -X POST -d "$DATA" -H "Authorization: key=<FCM SERVER KEY>"

FLUTTER_NOTIFICATION_CLICK必须调用onresume和onmessage

© www.soinside.com 2019 - 2024. All rights reserved.