【问题标题】:Firebase-admin doesn't send iOS APN notificationFirebase-admin 不发送 iOS APN 通知
【发布时间】:2017-06-21 19:03:35
【问题描述】:

我可以将来自Firebase Console Notifications 的推送通知发送到我的iOS 设备,它可以完美地作为前台和后台的应用程序。

当我尝试使用Firebase-admin by NodeJS 发送它们时,它仅在应用程序处于前台时有效,在后台没有任何反应。

我认为 FCM-APN 之间的通信很好,因为它适用于控制台。

这是我的 NodeJS 代码:

function sendFCM(registration_ids, data, collapseKey) {

    const options = {
        priority: "high",
        collapseKey : collapseKey,
        contentAvailable : true,
        timeToLive: 60 * 60 * 24
    };

    const payload = {
        data: data,
        notification: {
            title: "My title",
            text: "My description",
            sound : "default"
        }
    }

    admin.messaging().sendToDevice(registration_ids, payload, options)
        .then(function(response) {
            console.log("Successfully sent message:", response);
        })
        .catch(function(error) {
            console.log("Error sending message:", error);
        });
}

你认为它正在发生什么?你知道一些记录问题的方法吗?

【问题讨论】:

    标签: ios firebase push-notification firebase-cloud-messaging firebase-admin


    【解决方案1】:

    Server Protocol documentation 表示通知文本的键是body,而不是text。看看这种变化是否会产生影响:

    const payload = {
        data: data,
        notification: {
            title: "My title",
            body: "My description", // <= CHANGE
            sound : "default"
        }
    }
    

    【讨论】:

    • 谢谢!有两次失败。首先,你说的那个。其次,firebase json 很糟糕 :(。开发时间太长了......
    猜你喜欢
    • 1970-01-01
    • 2021-05-04
    • 2018-06-21
    • 2021-04-20
    • 2018-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-23
    相关资源
    最近更新 更多