Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.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
Reactjs firebase safari错误消息:此浏览器没有';t支持API';需要使用firebase SDK_Reactjs_Typescript_Firebase - Fatal编程技术网

Reactjs firebase safari错误消息:此浏览器没有';t支持API';需要使用firebase SDK

Reactjs firebase safari错误消息:此浏览器没有';t支持API';需要使用firebase SDK,reactjs,typescript,firebase,Reactjs,Typescript,Firebase,我们正在使用firebase 8.2.1版本。 我们正在使用react和typescript进行开发。 只有在safari中查看时才会发生错误。 错误为firebase错误:消息:此浏览器不支持使用firebase SDK所需的API。(消息/不支持的浏览器)。 我查看了以下文档,但只有safari不支持云消息。 我如何解决这个问题? 此处链接说明] 不幸的是,Safari上还不支持此功能,因此消息传递不起作用 在尝试使用之前请检查兼容性 let messaging = null; if (fi

我们正在使用firebase 8.2.1版本。
我们正在使用react和typescript进行开发。
只有在safari中查看时才会发生错误。 错误为firebase错误:消息:此浏览器不支持使用firebase SDK所需的API。(消息/不支持的浏览器)。
我查看了以下文档,但只有safari不支持云消息。
我如何解决这个问题?
此处链接说明]

不幸的是,Safari上还不支持此功能,因此消息传递不起作用

在尝试使用之前请检查兼容性

let messaging = null;
if (firebase.messaging.isSupported(){
    messaging = firebase.messaging();
}
有关.issuported()的详细信息,请参阅


Mac桌面上有需要支持的功能。

谢谢您的回复。我应该把上面的代码放在哪里?你应该在顶部声明代码。然后,您不必在prepareNotification中编写
firebase.messaging()
,而是编写
messaging.requestPermission()
。如果(!messaging)返回,不要忘记测试
或者您可能想提醒它不受支持。如果答案有帮助,请批准它。这是否意味着您可以通过编写类似“a”的内容来解决问题?不,因为现在您只需使用
prepareNotification
,您还需要在
prepareNotificationToken
中使用它。因此,与其写两次,不如在
firebase.apps.length
旁边声明它。除此之外,您需要使用
消息传递
而不是
firebase.messaging()
,检查
消息传递
是否为空。
export const prepareNotification = () => {
  let messaging = null;
  if (firebase.messaging.isSupported()) {
    messaging = firebase.messaging();
  }
  firebase
    .messaging()
    .requestPermission()
    .then(() => {
      prepareNotificationToken();
    })
    .catch(() => {
      console.log('Unable to get permission to notify.');
    });
};

export const prepareNotificationToken = () => {
  firebase
    .messaging()
    .getToken({ vapidKey: VAPID_KEY })
    .then((token) => {
      asyncNotificationToken(token).then(() => {
        console.log('Registed notification token.');
      });
    });
};
let messaging = null;
if (firebase.messaging.isSupported(){
    messaging = firebase.messaging();
}