-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirebase-messaging-sw.js
33 lines (28 loc) · 990 Bytes
/
firebase-messaging-sw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// [START initialize_firebase_in_sw]
importScripts('https://www.gstatic.com/firebasejs/5.5.9/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/5.5.9/firebase-messaging.js');
// messagingSenderId.
firebase.initializeApp({
'messagingSenderId': '223623084549'
});
// messages.
const messaging = firebase.messaging();
// [END initialize_firebase_in_sw]
messaging.setBackgroundMessageHandler(function(payload) {
console.log('[firebase-messaging-sw.js] Received background message ', payload);
/*
const notificationTitle = 'Background Message Title';
const notificationOptions = {
body: 'Background Message body.'
};
*/
// Customize notification here
const notificationTitle = payLoad.notification.title;
const notificationOptions = {
body: payLoad.notification.body,
icon: payLoad.notification.icon,
};
return self.registration.showNotification(notificationTitle,
notificationOptions);
});
// [END background_handler]