Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
firebase云消息传递不';在我的javascript web应用程序中不显示_Javascript_Firebase_Push Notification_Firebase Cloud Messaging - Fatal编程技术网

firebase云消息传递不';在我的javascript web应用程序中不显示

firebase云消息传递不';在我的javascript web应用程序中不显示,javascript,firebase,push-notification,firebase-cloud-messaging,Javascript,Firebase,Push Notification,Firebase Cloud Messaging,当我必须在web应用程序中显示firebase推送通知时,我遇到了问题。这很奇怪,因为如果我从邮递员那里取回,我可以看到通知出现在我的桌面上,但是如果我从我的web应用程序中取回,我看不到它 这是我的提取代码: let obj = { to: deviceToken, data: { notification: { title: "Test Title", body: &quo

当我必须在web应用程序中显示firebase推送通知时,我遇到了问题。这很奇怪,因为如果我从邮递员那里取回,我可以看到通知出现在我的桌面上,但是如果我从我的web应用程序中取回,我看不到它

这是我的提取代码:

let obj = {
        to: deviceToken,
        data: {
          notification: {
            title: "Test Title",
            body: "Test body",
            icon: myIcon,
          },
        },
        priority: "high"
      };

      fetch("https://fcm.googleapis.com/fcm/send", {
        method: "POST",
        body: JSON.stringify(obj),
        cache: 'no-cache',
        headers: {
          "Content-Type": "application/json",
          Authorization:
            `key=${myApiKey}`,
        },
      })
      .then((response) => {
        console.log(response);
      })
      .catch((err) => {
        console.log(err);
      });
和firebase-messaging-sw.js

messaging.setBackgroundMessageHandler(function(payload) {
  console.log(
    "[firebase-messaging-sw.js] Received background message ",
    payload
  );

  var obj = JSON.parse(payload.data.notification);
  
  // Customize notification here
  var notificationTitle = obj.title;
  var notificationOptions = {
    body: obj.body,
    icon: obj.icon,
  };

  return self.registration.showNotification(
    notificationTitle,
    notificationOptions
  );
});
有人能帮我吗