我正在尝试在特定用户的设备上发送推送通知,因此我为此创建了云功能,您可以在下面的部分中看到云功能代码。云功能成功运行,没有任何错误,但是通知不会在用户设备中弹出。在这里,我添加了云功能代码以及日志附件。
我还尝试了不同的解决方案,例如通过点击API并通过失败也发送通知。所以编码员可以帮助我跳出这个问题。
index.js
let functions = require('firebase-functions');
let admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref('/projects/{projectId}').onWrite(event => {
var registrationToken = 'YOUR_Registration_Token';
var message = {
notification : {
body : 'This is a Firebase Cloud Messaging Topic Message!',
title : 'FCM Message'
},
data: {
score: '850',
time: '2:45'
},
token: registrationToken
};
// Send a message to the device corresponding to the provided
// registration token.
admin.messaging().send(message)
.then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
return null;
})
.catch((error) => {
console.log('Error sending message:', error);
});
console.log('hello');
});