我正尝试在预定日期自动向我的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);
});
当我尝试在数据库上为消息添加名称和文本时,什么也没发生