TypeError: admin.messaging.sendToDevice is not a function , using firebase functions

TypeError: admin.messaging.sendToDevice is not a function , using firebase functions

在使用以下功能时,我开始向设备发送通知我在用于消息传递的 firebase 云功能中收到此错误

TypeError: admin.messaging.sendToDevice is not a function

return admin.messaging.sendToDevice(to_token_id,payload).then(result=>{

            console.log("Notification Sent Successful");
            return null;
        });

是否已弃用上述方法? 如果是这样,那么新的是什么? 上面的firebase云函数写在javascript.

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