Created
July 2, 2018 09:28
-
-
Save goofmint/30f3cb2b28cb45f66e1db94205a52225 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
if (!('serviceWorker' in navigator)) { | |
// Service Worker非対応 | |
} | |
navigator.serviceWorker.register('./serviceworker.js') | |
.then(() => { | |
if (!('showNotification' in ServiceWorkerRegistration.prototype)) { | |
// プッシュ通知がサポートされていない場合 | |
return; | |
} | |
if (Notification.permission === 'denied') { | |
// プッシュ通知を拒否された場合 | |
return; | |
} | |
if (!('PushManager' in window)) { | |
// PushManagerが存在しない場合 | |
return; | |
} | |
return navigator.serviceWorker.ready; | |
}) | |
.then(serviceWorkerRegistration => { | |
return serviceWorkerRegistration.pushManager.getSubscription(); | |
}) | |
.then(subscription => { | |
if (!subscription) { | |
// すでに購読中 | |
} else { | |
// 未購読 | |
console.log(subscription.toJSON()); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment