【问题标题】:how to send FCM message to certain Platform and last app engagement?如何将 FCM 消息发送到某个平台和最后的应用程序参与?
【发布时间】:2021-10-04 22:53:44
【问题描述】:
在 Firebase 控制台中,我可以像这样根据应用平台和最后一次应用参与发送 FCM 消息
目前我正在使用 Node JS Cloud 功能和 Firebase Admin SDK,并且我想基于平台(Android 或 iOS)和上次应用程序参与以编程方式发送 FCM 消息,就像上面的控制台一样。
如何以编程方式做到这一点?我试图找到文档,但我找不到它:(
【问题讨论】:
标签:
node.js
firebase
google-cloud-functions
firebase-cloud-messaging
【解决方案1】:
有一种方法可以将它们发送到特定平台。例如:
const topicName = 'industry-tech';
const message = {
notification: {
title: 'Sparky says hello!'
},
android: {
notification: {
imageUrl: 'https://foo.bar.pizza-monster.png'
}
},
apns: {
payload: {
aps: {
'mutable-content': 1
}
},
fcm_options: {
image: 'https://foo.bar.pizza-monster.png'
}
},
webpush: {
headers: {
image: 'https://foo.bar.pizza-monster.png'
}
},
topic: topicName,
};
admin.messaging().send(message)
.then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
})
.catch((error) => {
console.log('Error sending message:', error);
});
您可以查看更多信息here。