yut*_*yut 4 firebase typescript reactjs
我们使用的是 firebase 8.2.1 版本。
我们正在使用 React 和 TypeScript 进行开发。
仅当我在 safari 中查看时才会出现该错误。错误是 FirebaseError: Messaging: 此浏览器不支持使用 firebase SDK 所需的 API。(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.');
});
});
};
Run Code Online (Sandbox Code Playgroud)
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.');
});
});
};
Run Code Online (Sandbox Code Playgroud)
小智 9
遗憾的是 Safari 尚不支持Push API ,因此消息功能无法使用。
在尝试使用之前检查兼容性。
let messaging = null;
if (firebase.messaging.isSupported()){
messaging = firebase.messaging();
}
Run Code Online (Sandbox Code Playgroud)
有关 .isSupported() 的详细信息,请参阅文档。
有一个功能请求支持Mac 桌面上的safari 推送通知。
| 归档时间: |
|
| 查看次数: |
10382 次 |
| 最近记录: |