我正在使用web-push库通过node server发送推送通知。目前,我只能从后端发送标题。有没有办法从后端发送图片?
发布于 2020-02-15 11:37:38
这是发送带有图像的通知的示例函数:
function sendPushNotification(req, res) {
const subscriptionId = req.params.id;
const pushSubscription = subscriptions[subscriptionId];
webpush
.sendNotification(
pushSubscription,
JSON.stringify({
title: "your title",
text: "your text",
image: "path/to/image.jpg",
tag: "new...",
url: "/your-url.html"
})
)
.catch(err => {
console.log(err);
});
res.status(202).json({});
}这是来自Lorenzo Spyna的,它解释了如何在这个tutorial中做到这一点,你可以在github的this project中看到所有代码
https://stackoverflow.com/questions/60235512
复制相似问题