Skip to content

Instantly share code, notes, and snippets.

@cionman
Created November 29, 2017 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cionman/e07e6767f133ee193712e0992f9c426c to your computer and use it in GitHub Desktop.
Save cionman/e07e6767f133ee193712e0992f9c426c to your computer and use it in GitHub Desktop.
서비스워커 파일
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