【问题标题】:cordova fcm push notifications using firebase functions issue科尔多瓦 fcm 使用 firebase 功能推送通知问题
【发布时间】:2019-04-15 23:41:37
【问题描述】:

我正在使用 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。

【问题讨论】:

    标签: android firebase google-cloud-functions cordova-plugin-fcm


    【解决方案1】:

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

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

    Documentation

    【讨论】:

    • 这是 android 的特定要求吗?在 ios 中,我的代码可以很好地处理所需的数据
    • 我不确定我害怕,没有太多的iOS经验。您是否尝试过添加数据数组?
    • 我要试试这个
    猜你喜欢
    • 2015-11-24
    • 1970-01-01
    • 2017-09-06
    • 1970-01-01
    • 2016-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-13
    相关资源
    最近更新 更多