使用 firebase 函数问题的 cordova fcm 推送通知

cordova fcm push notifications using firebase functions issue

我正在使用 firebase 函数并发送如下通知

 let pushPayload = {
        notification: {
            title: 'Doodles Notification',
            body: "push testing",
            sound: 'default',
            badge: '1'
            }
    };

    //push tokens need to be of customer as well as all the admins in the system. fetch admin push tokens
    admin.messaging().sendToDevice(pushToken, pushPayload).then(
        (resp) => {
                        console.log("push notification sent using test method")
                        return
                }
    ).catch(
        (err) => {
                    console.log("Error sending push notification:" + JSON.stringify(err))
                    return
        }
    )

客户端离子应用程序有如下方法:

  this.fcm.onNotification().subscribe(data => {
            console.log("push message is:" + JSON.stringify(data))
            alert(data.aps.alert.body)
          });

在 ios 这一切都很好。但是在 android 上,console.log 打印

{"wasTapped":false}

我对上述预期没问题 属性 但是数据在哪里? firebase 文档围绕它令人困惑,我有点迷失了我需要使用的正确负载是什么,它适用于 ios 和 android。

您的 pushPayload 还需要有一个 data 数组来传递数据。我相信你也需要在你的按键周围做语音标记:

"notification":{  
   "title":"Doodles Notification",
   "body":"push testing",
   "sound":"default",
   "badge":"1"
},
"data":{  
   "Key1":"Test",
   "Key2":"More data"
}

Documentation