gpt4 book ai didi

firebase - Flutter - FirebaseMessaging.onMessageOpenedApp.listen 未触发

转载 作者:行者123 更新时间:2023-12-04 14:55:25 24 4
gpt4 key购买 nike

我在用:

flutter version 2.2
firebase_messaging: ^10.0.2
我收到推送通知,然后单击它并打开应用程序。
然后我看不到 FirebaseMessaging.onMessageOpenedApp.listen被调用(回调正在向我发送调试电子邮件,但我没有收到任何邮件)
我的问题是
  • (可选)如何使用上面的 android studio debugur 模拟案例调试 android 应用程序,因此应用程序被杀死而不打开,然后通过通知打开
  • 这里有什么问题?为什么不触发该流?我在 main.dart 中初始化它

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

    最佳答案

    要在您的情况下查看应用程序被杀死时的日志,您是否尝试过 flutter logs命令,只需将您的设备插入 USB 调试并运行 flutter logs在你的终端里你所有的 print消息将显示在此处。
    关于 FirebaseMessaging.onMessageOpenedApp.listen启动应用程序时被调用是因为您需要定义后台消息处理程序

    /// Define a top-level named handler which background/terminated messages will
    /// call.
    ///
    /// To verify things are working, check out the native platform logs.
    Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
    // If you're going to use other Firebase services in the background, such as Firestore,
    // make sure you call `initializeApp` before using other Firebase services.
    await Firebase.initializeApp();
    print('Handling a background message ${message.messageId}');
    }
    在此处查看完整的 firebase_messaging 示例 main.dart

    关于firebase - Flutter - FirebaseMessaging.onMessageOpenedApp.listen 未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68119898/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com