所以我按照这个firebase教程看似我根据文档做了所有事情,但我仍然遇到错误。 Youtube FCM Tutorial
var config = {
apiKey: "AIzaSyAyWVXB9KFLm2ymoBoiY-TothNYgo3IrtA",
authDomain: "fir-end-cff84.firebaseapp.com",
databaseURL: "https://fir-end-cff84.firebaseio.com",
projectId: "fir-end-cff84",
storageBucket: "fir-end-cff84.appspot.com",
messagingSenderId: "297653223714"
};
firebase.initializeApp(config);
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('./firebase-messaging-sw.js').then(function (registration) {
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}).catch(function (err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
}
const messaging = firebase.messaging();
messaging.requestPermission()
.then(function () {
console.log('Have Permit');
return messaging.getToken();
})
.then(function (token) {
console.log(token);
})
.catch(function (err) {
console.log(err);
})
这是项目概述:
我在ubuntu 16.04上使用最新版本的webstorm
编辑:我甚至使用过这个回购但仍然有同样的问题 https://github.com/firebase/quickstart-js/tree/master/messaging
答案 0 :(得分:0)
为了获得你的localhost需要具有应用服务器功能的fcm令牌,一些webstorm的localhost不会这样做!