【发布时间】:2017-11-14 10:28:38
【问题描述】:
情况如下:我有一个 firebase 云函数,它在每次写入某个数据库集合(称为“jamrooms”)时运行。 NodeJS脚本如下:
const functions = require('firebase-functions');
// The Firebase Admin SDK to access the Firebase Realtime Database.
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.newJamroom = functions.database.ref('/jamrooms/{jamroomId}').onWrite(event => {
// Grab the current value of what was written to the Realtime Database.
var jamroomId = event.params.jamroomId;
var topic = "new-jamroom";
var payload = {
data: {
title: "New jamroom available !",
body: String("Jamroom id = ").concat(jamroomId)
}
};
// Send a message to devices subscribed to the provided topic.
return admin.messaging().sendToTopic(topic, payload)
.then(function (response) {
// See the MessagingTopicResponse reference documentation for the
// contents of response.
console.log("Successfully sent message:", response);
})
.catch(function (error) {
console.log("Error sending message:", error);
});
});
在客户端(Android)上,我订阅了“new-jamroom”主题:
FirebaseMessaging.getInstance().subscribeToTopic("new-jamroom");
每次向集合中添加新的键值对时,脚本都会成功执行:
但客户端永远不会在后台或前台收到通知。
我不知道从哪里看才能了解哪里出了问题。
更新
即使从控制台发送通知(使用控制台中存在的主题“new-jamroom”)也不会将其发送到客户端(发送了 Firebase 记录 0)。
【问题讨论】:
标签: android firebase firebase-cloud-messaging