代码之家  ›  专栏  ›  技术社区  ›  pedrommuller

浏览器中未显示Firebase FCM http v1图标

  •  0
  • pedrommuller  · 技术社区  · 6 年前

    我在跟踪 this tutorial ,到目前为止,我已经有了适用于web浏览器的通知(在chrome中测试)

    {
        'message': {
         token,
         'notification': {
             title,
             body,
             icon // <-- added the icon              
             }
        }
    }
    

    如果我试图在消息有效负载中添加图标,那么当我向google FCM URL发送帖子时,会收到一个错误的请求。

    它在没有向负载添加icon属性的情况下工作,显然,这就是错误,问题再次是如何发送负载中的图标来工作。

    谢谢

    async function notification(messageBody) {
        const api = 'https://fcm.googleapis.com/v1/projects/{projectID}/messages:send';
        const accessToken = await getAccessToken();
        const response = await fetch(api, {
            headers: {
                'Accept': 'application/json',
                'Content-type': 'application/json',
                'Authorization': `Bearer ${accessToken}`
            },
            method: 'POST',
            body: messageBody
        });
        return response;
    }
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   James Poag    6 年前

    {
      "message": {
        "token" : token,
        "notification": {
          "title": title,
          "body": body
        },
        "webpush": {
          "headers": {
            "Urgency": "high"
          },
          "notification": {
            "body": body,
            "requireInteraction": "true",
            "icon": icon
          }
        }
      }
    }