我通过通知api进行了通知设置,以在页面加载时触发。一旦它开始工作,我将在以后添加一些cookie,仅显示一次。我在MVC项目上具有相同的设置,并且没有任何问题。该网站是通过.html文件传送的,不会触发通知。 http://www.freedomoveraddiction.org
// Initialize Firebase
var config = {
apiKey: "####",
authDomain: "###.firebaseapp.com",
databaseURL: "https://###.firebaseio.com",
projectId: "foa-notifications",
storageBucket: "###.appspot.com",
messagingSenderId: "###"
};
firebase.initializeApp(config);
//get database
var database = firebase.database().ref().child("notifications/");
if (Notification.permission === "granted") {
database.on('child_added', function (data, ChildKey) {
if (Notification.permission === "granted") {
var title = data.val().title;
var action = data.val().action
var message = data.val().message;
var icon = data.val().icon;
var key = ChildKey;
console.log(action);
var e = new Notification(title, {
body: message,
icon: icon,
requireInteraction: true,
click: action,
tag: key
});
}
});
} else {
if (Notification.permission !== 'denied') {
Notification.requestPermission().then(function (permission) {
if (Notification.permission === 'granted') {
var e = new Notification(title, {
body: message,
icon: icon,
requireInteraction: true,
click: action,
tag: key
});
}
});
}
}