【发布时间】:2020-02-26 06:04:54
【问题描述】:
我试图使用 firebase admin sdk 从 firebase 云功能向主题发送多条消息。但是,如果设备没有连接到网络,那么我打开网络连接我只会收到我在我的 android 应用程序上的 onMessageReceived() 方法中发送的最后一条消息。我想接收设备未连接到互联网时发送的所有消息。
我的云功能代码:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.showNotification = functions.https.onCall((data,context) => {
var topic = 'weather';
var message = {
data: {
title: 'This is title',
description: getRandomString(15)
},
topic: topic,
android : {
ttl : 86400
}
};
// Send a message to devices subscribed to the provided topic.
admin.messaging().send(message)
.then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
return response;
})
.catch((error) => {
console.log('Error sending message:', error);
});
});
【问题讨论】:
标签: javascript android firebase firebase-cloud-messaging google-cloud-functions