Firebase云功能在Cordova上不起作用

时间:2019-09-04 01:47:12

标签: firebase cordova push-notification google-cloud-functions

我正尝试在预定日期自动向我的Cordova应用程序中的每个用户发送通知。我尝试创建一个云函数,但在Firebase上的登录未显示任何错误。

我尝试执行此功能,并且我使用cordova-plugin-firebase-lib来接收通知,如果我转到firebase控制台并手动发送它会起作用

//import firebase functions modules
const functions = require('firebase-functions');
//import admin module
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);


// Listens for new messages added to messages/:pushId
exports.pushNotification = functions.database.ref('/messages/{pushId}').onWrite( event => {

    console.log('Push notification event triggered');

    //  Grab the current value of what was written to the Realtime Database.
    var valueObject = event.data.val();

    if(valueObject.photoUrl !== null) {
      valueObject.photoUrl= "Sent you a photo!";
    }

  // Create a notification
    const payload = {
        notification: {
            title:valueObject.name,
            body: valueObject.text || valueObject.photoUrl,
            sound: "default"
        },
    };

  //Create an options object that contains the time to live for the notification and the priority
    const options = {
        priority: "high",
        timeToLive: 60 * 60 * 24
    };


    return admin.messaging().sendToTopic("pushNotifications", payload, options);
});

当我尝试在数据库上为消息添加名称和文本时,什么也没发生

0 个答案:

没有答案