【发布时间】:2018-02-22 10:55:03
【问题描述】:
我尝试让多个推送通知在 Cloud Functions for Firebase 上运行,但没有成功。
我将我的消息回执存储在一个节点中
- message_receipts
- -KtvyTN3nbVKoFjHdpJg
- hHhs5Aco38X1W8EhaaxrwsQDXwy1:"收据"
- nI25FjUnBfQiCWzdCUIAe8CWTPQ2:"收据"
要发送推送通知,我尝试使用云功能:
//*********************************************************************************************************** */
//handle lsit item added by shared user
if (String(msgData.messageType) == 'ListItemAddedBySharedUser') {
return admin.database().ref("message_receipts").child(event.params.messageID).once('value').then(receipts => {
receipts.forEach(function (receipt) {
//Send push to receipt
return admin.database().ref('/users/' + receipt.key).once('value').then(usnap => {
//Send push to users fcmToken
const userSnap = usnap.val()
console.log('sending Push to ' + userSnap.fcmToken)
//create Notification Payload
var payload = {
notification: {
title: msgData.title,
body: msgData.message,
badge: '1',
sound: 'default',
sbID: String(event.data.key),
senderID: msgData.senderID,
listID: msgData.listID,
receiptID: receipt.key,
notificationType: String(msgData.messageType),
}
};
return admin.messaging().sendToDevice(userSnap.fcmToken, payload).then(response => {
console.log("Successfully sent invite message:", response)
console.log(response.results[0].error)
}).catch((err) => { console.log("Error sending Push", err) })
})
})
})
} //*********************************************************************************************************** */
我得到的只是发送了一个通知。 我对 java 脚本和云函数很陌生。 我需要做什么才能通知我的所有用户?
【问题讨论】:
-
您好,您介意发布您完成的解决方案吗?很想看看。
标签: firebase firebase-cloud-messaging google-cloud-functions