2017-11-27 1 views
1

Ich entwickle ein Web mit Benachrichtigung push wie whatssap, ich benutze Firebase Cloud-Nachricht dafür, ich versuche, Benachrichtigung von Firebase-Konsole mit Token zu senden, aber ich bekomme nichts in den Konsolenprotokollen , nicht einmal FehlerKann keine Nachricht von Firebase in React.js empfangen

Dies wird de-Feuerbasis Messaging-sw.js

importScripts('https://www.gstatic.com/firebasejs/4.3.0/firebase-app.js'); 
importScripts('https://www.gstatic.com/firebasejs/4.3.0/firebase-messaging.js'); 
importScripts('https://www.gstatic.com/firebasejs/4.3.0/firebase.js'); 

firebase.initializeApp(config); 

const messaging = firebase.messaging(); 

messaging.setBackgroundMessageHandler(function(payload) { 
    console.log('[firebase-messaging-sw.js] Received background message ', payload); 
    // Customize notification here 
    const notificationTitle = 'Background Message Title'; 
    const notificationOptions = { 
     body: 'Background Message body.', 
     icon: '/firebase-logo.png' 
    }; 

return self.registration.showNotification(notificationTitle, 
    notificationOptions); 
}); 

dies ist die index.html

<script src="https://www.gstatic.com/firebasejs/4.3.0/firebase-app.js"></script> 
    <script src="https://www.gstatic.com/firebasejs/4.3.0/firebase-messaging.js"></script> 
    <script src="https://www.gstatic.com/firebasejs/4.3.0/firebase.js"></script> 

    <script> 
     firebase.initializeApp(config); 
     const messaging = firebase.messaging(); 
     messaging.onMessage(function(payload) { 
     console.log("Message received. ", payload); 
     // ... 
     }); 
    </script> 

Antwort

1

ich glaube nicht Messaging vor Ort funktioniert. Sie müssen auf HTTPS hosten. Ich hatte ein ähnliches Problem. Dann habe ich meine App auf Firebase gehostet und alles hat funktioniert.

+0

Oh, ich muss dieses Web in einem Cloud Server bereitstellen, also wenn ich es mache, sollte es dann funktionieren? –

+1

Wenn Sie https verwenden. Das hat es für mich behoben. –

Verwandte Themen