繁体   English   中英

firebase safari 错误消息:此浏览器不支持使用 firebase08ABB354C 所需的 API

[英]firebase safari error Messaging: This browser doesn't support the API's required to use the firebase SDK

我们使用的是 firebase 8.2.1 版本。
我们正在使用 react 和 typescript 进行开发。
仅当我在 safari 中查看时才会出现该错误。 错误是 FirebaseError: Messaging: This browser does not 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[在此处输入链接描述] 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.');
      });
    });
};

一个

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

遗憾的是,Safari 尚不支持推送API,因此消息传递不起作用。

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

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

有关.isSupported() 的详细信息,请参阅文档

在 Mac 桌面上支持safari 推送通知功能请求

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM