пусть имя моего сайта будет www.example.com У меня есть веб-приложение, созданное в консоли Firebase. Я интегрировал в него функцию облачных сообщений FireBase только из FireBase. я получаю уведомление, но когда я нажимаю на него, я не перенаправляю на webiste, или ничего не происходит, уведомление просто закрывается.
это firebase-messaging-sw. js
importScripts('https://www.gstatic.com/firebasejs/3.5.2/firebase-messaging.js');
firebase.initializeApp({
'messagingSenderId': '#########'
});
const messaging = firebase.messaging();
messaging.setBackgroundMessageHandler(function(payload)
{
console.log('[firebase-messaging-sw.js] Received background message ', payload);
console.log("body",payload.data.body);
const notificationTitle = 'Background Message Title';
const notificationOptions = {
body: 'Background Message body.',
};
return self.registration.showNotification(notificationTitle,
notificationOptions);
});
это код, который у меня есть в моем индексе
onst messaging = firebase.messaging();
messaging.usePublicVapidKey("#############################################################################");
messaging.requestPermission().then(function()
{
messaging.getToken().then(function(currentToken)
{
}).catch(function(err){
console.log('An error occurred while retrieving token. ', err);
showToken('Error retrieving Instance ID token. ', err);
setTokenSentToServer(false);
});
}).catch(function(err){
console.log('An error occurred while getting permission', err);
});
messaging.onMessage((payload) => {
console.log('Message received. ', payload);
appendMessage(payload);
});