在使用以下功能时,我正在向设备发送设备通知,我在用于消息传递的 firebase 云功能中收到此错误TypeError:admin.messaging.sendToDevice 不是函数return admin.messaging.sendToDevice(to_token_id,payload).then(result=>{ console.log("Notification Sent Successful"); return null; });上述方法是否已弃用?如果是这样,那么新的是什么?上面的firebase cloud函数是用javascript写的。
1 回答
摇曳的蔷薇
TA贡献1793条经验 获得超6个赞
sendToDevice,你需要使用方法send():
// The topic name can be optionally prefixed with "/topics/".
var topic = 'highScores';
var message = {
data: {
score: '850',
time: '2:45'
},
topic: topic
};
// 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);
})
.catch((error) => {
console.log('Error sending message:', error);
});
https://firebase.google.com/docs/cloud-messaging/android/send-multiple#build_send_requests
添加回答
举报
0/150
提交
取消