reactjs - firebase safari 错误消息 : This browser does

我们使用的是 firebase 8.2.1 版本。
我们正在使用 React 和 TypeScript 进行开发。
仅当我在 safari 中查看时才会出现该错误。 错误是 FirebaseError: Messaging: This browser doesn't support the API's required to use the firebase SDK.(messaging/unsupported-browser).
看了下面的文档,只有safari不支持云消息。
我该如何解决这个问题?
https://firebase.google.com/support/guides/environments_js-sdk?hl=ja[enter此处链接描述] 1

import firebase from 'firebase/app';
import 'firebase/messaging';
import { asyncNotificationToken } from 'apis/asyncNotificationToken';

const firebaseConfig = {
  apiKey: '******************',
  projectId: '******',
  messagingSenderId: '*******',
  appId: '********',
};

const VAPID_KEY =
  '******************************';

if (firebase.apps.length < 1) {
  firebase.initializeApp(firebaseConfig);
}

export const prepareNotification = () => {
  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.');
      });
    });
};

a

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.');
      });
    });
};

最佳答案

悲哀Push API Safari 尚不支持 Messaging,因此无法使用 Messaging。

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

let messaging = null;
if (firebase.messaging.isSupported(){
    messaging = firebase.messaging();
}

参见 documentation有关 .isSupported() 的详细信息。

有一个feature request支持safari push notification在 Mac 桌面上。

关于reactjs - firebase safari 错误消息 : This browser doesn't support the API's required to use the firebase SDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65574164/

相关文章:

javascript - 如果 "any"不能在 Nest.js 中使用,模式中的字段类型应该是什么

deep-learning - 如何通过一次操作合并两个 torch.utils.data 数据加载

powershell - 无法注册 PS 图库

c# - 有没有办法在 Switch 表达式中跳过或继续,或者每个分支都需要返回一些东西?

c# - 将 RestSharp 用于以下代码的内置替代方法是什么?

c - STM32创建RAM段

java - 在 Clojure 中使用 JSoup 解析字符串

python - numpy 中的 3d 矩阵乘法

c++ - 找不到 Glog(缺少 : GLOG_INCLUDE_DIR GLOG_LIBRARY)

awk - 将 awk 应用于除第一行以外的所有内容