flutter - 当应用程序通过使用 firebase_messaging 的推送通知终止时如何接收自定义数据?

标签 flutter firebase-cloud-messaging

如标题所示,当用户在应用程序终止时单击通知时,为了接收自定义数据,当前的解决方法是什么?

看起来像在 Android 上 is not possible在 onLaunch 中接收数据消息(这是理想的方式) 在 IOS 上我还没有尝试过,因为我首先面临这个问题。

有什么线索吗?

其他信息:我通过 firebase 云函数 发送的通知采用以下形式:

  "message":{
    "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "notification":{
      "title":"Portugal vs. Denmark",
      "body":"great match!"
    },
    "data" : {
      "Nick" : "Mario",
      "Room" : "PortugalVSDenmark"
    }
  }
}

https://firebase.google.com/docs/cloud-messaging/concept-options

onResume 上,我能够执行操作,但 onLaunch 似乎没有被调用。

最佳答案

这是您的有效负载应采用的包含数据的格式。它确实有效,因为这就是我让它在我的项目中工作的方式。此外,为了让一切正常工作,还有一个 answer here这可能对一般项目设置有帮助:

 {
      notification: {
        title: 'A title',
        body: 'The body.'
      },
      data: {
        // your data here
      },
      android: {
        ttl: 3600 * 1000,
        notification: {
          click_action: 'FLUTTER_NOTIFICATION_CLICK'
        }
      },
      // The below is for iOS specific properties
      // apns: {
      //   payload: {
      //     aps: {
      //       badge: 42
      //     }
      //   }
      // },
      tokens: [] // or a single 'token'
    }

关于flutter - 当应用程序通过使用 firebase_messaging 的推送通知终止时如何接收自定义数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58215126/

相关文章:

firebase - cordova-plugin-fcm - 未定义 FCMPlugin

javascript - 如何重新请求在 Firebase Cloud Messaging 中显示通知的权限?

firebase-cloud-messaging - 指令 "https://www.gstatic.com/"中的浏览器扩展不安全 CSP 值 'script-src'

ios - 从FCM通知数据IOS中检索数据并打开 View Controller

ios - 如何在 Xcode 中更改 $(PRODUCT_BUNDLE_IDENTIFIER)?

flutter - 向 Flutter 布局添加 Logo

ios - Apple 开发者仪表板 - 应用程序 ID 部分缺失

flutter - TextFormField 启用后未聚焦

flutter - block 测试错误: No method stub was called from within `when()`

flutter - flutter 中 ScrollView 内的Listview