Flutter - FirebaseMessaging.onMessageOpenedApp.listen 未触发

2024-03-01

我在用:

flutter version 2.2
firebase_messaging: ^10.0.2

我收到推送通知,然后单击它并打开应用程序。 然后我就看不到了FirebaseMessaging.onMessageOpenedApp.listen接到电话(回调正在向我发送调试电子邮件,但我没有收到任何邮件)

我的问题是

  1. (可选)如何使用 android studio debugur 模拟上面的情况来调试 android 应用程序,以便应用程序被杀死而不打开,然后通过通知打开

  2. 这里可能有什么问题?为什么该流没有被触发?我在 main.dart 中初始化它

PS:所有其他方法都可以正常工作,因此如果应用程序位于前台,则 onMessage.listen 效果很好。我需要处理 onMessageOpenedApp,以便我可以根据通知信息将用户重定向到正确的视图


对于第一个问题:

To view the logs from your app, you can use the 'Logcat' tab in Android Studio or IntelliJ: enter image description here

对于第二个问题:

如果您的应用程序被终止并且您希望收到通知点击回调,您应该使用:

FirebaseMessaging.instance.getInitialMessage().then((message) {
  if (message != null) {
    // DO YOUR THING HERE
  }
});

,因为根据Flutter团队对onMessageopenedApp函数的注释:

 /// If your app is opened via a notification whilst the app is terminated,
  /// see [getInitialMessage].
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Flutter - FirebaseMessaging.onMessageOpenedApp.listen 未触发 的相关文章

随机推荐