首页 > 解决方案 > 使用 Firebase Admin SDK 发送带有图像负载的推送通知

问题描述

我正在尝试通过firebase admin sdk发送推送通知,但图像以某种方式未显示在推送通知中。

奇怪的是,当我在通知对象中使用无效键(如image)时,我得到一个错误。所以我假设我指定了正确的键。可以在此处找到通知文档。

以下代码成功发送推送通知,但用户手机上没有显示图像:

const admin = require('firebase-admin');
const app = admin.initializeApp({...}); // authenticated with credentials json file

await app.messaging().sendMulticast({
  notification: {
    title: "hello User",
    body: "This is a push notification with an image",
    imageUrl: "https://example.com/myPublicImage.png",
  },
  tokens: ["device_token_1", "device_token_2","..."]
});

标签: node.jsfirebasefirebase-cloud-messagingfirebase-admin

解决方案


推荐阅读