且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何向特定用户的Firebase发送推送通知

更新时间:2023-01-15 19:07:39

这就是我所做的.而且有效.我知道,因为我整夜都在努力使这件事起作用.

This is what I did. And it works. I know, because I was up all night trying to get this thing to work.

admin.messaging().sendToDevice(token, msg)
.then(resMsg => {
   console.log("Successfully sent message", resMsg);
}).catch(err => {
   console.log("Error sending message", err);
})

其中令牌是来自客户端设备的FCM令牌.而味精是具有以下结构的JSON负载:

Where token is the FCM token from the client device. And the msg is a JSON payload of the following structure:

const msg ={ 
             notification: {
               title: 'It\'s the last day of the week!',
               body: `It's Sunday! Don't forget to refresh Dashboard with your latest activity data!`,
             }, 
           };

来源构建一个仅使用Firebase的事务性推送通知系统