-
-
Save cionman/e07e6767f133ee193712e0992f9c426c to your computer and use it in GitHub Desktop.
서비스워커 파일
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
importScripts('https://www.gstatic.com/firebasejs/4.6.1/firebase-app.js'); | |
importScripts('https://www.gstatic.com/firebasejs/4.6.1/firebase-messaging.js'); | |
firebase.initializeApp({ | |
'messagingSenderId': '151504463082' //이곳은 자신의 프로젝트 설정 => 클라우드 메세징 => 발신자ID를 기입 | |
}); | |
const messaging = firebase.messaging(); | |
self.addEventListener('push', function(event) { | |
const payload = event.data.json(); | |
const title = payload.notification.title; | |
const options = { | |
body: payload.notification.body, | |
icon: payload.notification.icon, | |
data: payload.notification.click_action | |
}; | |
event.waitUntil(self.registration.showNotification(title, options)); | |
}); | |
self.addEventListener('notificationclick', function(event) { | |
console.log(event.notification); | |
event.notification.close(); | |
event.waitUntil( | |
clients.openWindow(event.notification.data) | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment