firebase-应用关闭时无法接收通知

时间:2018-08-28 07:19:00

标签: firebase notifications

将新的孩子添加到数据库后,我正在使用firebase-functions通过topic-messaging向用户发送通知。到目前为止,通知运行良好,但只有在应用程序位于foregroundbackground中时才会收到通知,

对此不满意,因为当用户从任务管理器中滑动应用程序时,通知不会显示。我已经尝试过在线解决方案列表,但没有任何结果。 link1 link2

index.js

var functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.sendNotification = functions.database.ref("/Global").onWrite(event => {
//Notification Message
    var payload = {
        notification: {
            title: "A new homily has been added!",
            body: "Click to read for today"
            icon: "default"

        }
    };

    if (event.data.previous.exists()) {
        if (event.data.previous.numChildren() < event.data.numChildren()) {
            return admin.messaging().sendToTopic("latest_events", payload);
        } else {
            return;
        }
    }

    if (!event.data.exists()) {
        return;
    }

    return admin.messaging().sendToTopic("latest_events", payload);

});

0 个答案:

没有答案