我们使用的是 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/