gpt4 book ai didi

react 原生 FCM : Can't access notification data when the app is in background or killed

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

我正在尝试使用 firebase 云消息传递和 react-native 应用程序来制作 react-native-fcm。

我主要专注于Android

react-native@0.48.0
react-native-fcm@10.0.2
OS: Android - Emulator - 7.0.2

当我的应用程序处于前台时,它运行良好,我在此函数中接收数据
FCM.on(FCMEvent.Notification, async (notif) => {
我可以处理一切

image

但是当应用程序在后台时,收到通知,但是当我点击横幅时,应用程序进入前台,触发相同的功能,但notif对象不同,并且不包含我的数据。

image

当应用程序被杀死时,也会收到通知,但是当我点击横幅时,应用程序启动, FCM.getInitialNotification()被触发,并且我的 notif 对象也不包含数据,与后台的行为相同

image

我正在使用 node-gcm 库和 firebase Web 界面测试消息的格式,但没有任何效果。

这是我的消息示例,但我尝试了大量组合:
let message = new gcm.Message({
priority: 'high',
content_available: true,
timeToLive: 3,
data: {
key1: 'message1',
key2: 'message2'
},
notification: {
title: "Hello, World",
icon: "ic_launcher",
body: "This is a notification that will be displayed if your app is in the background."
},
custom_notification: {
key1: 'message1',
key2: 'message2'
}

});

在这些情况下,我应该如何继续发送和接收数据?因为让我发疯。

如果您需要更多数据,请索取:)

谢谢!!

最佳答案

就我而言,在前台通知事件 firebase.notifications().onNotification 上构建通知时,我缺少通知的数据设置

new firebase.notifications.Notification()
.setNotificationId(fcmNotification.data.notificacionId)
.setTitle(fcmNotification.title)
.setBody(fcmNotification.body)
.setData(fcmNotification.data) // <- this little bastard

所以,当点击通知时 datafirebase.notifications().onNotificationOpened 上未定义即使在 firebase.notifications().onNotification 中的 json 中填充了数据字段

关于 react 原生 FCM : Can't access notification data when the app is in background or killed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46863132/

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