Created
July 2, 2018 09:26
-
-
Save goofmint/ab5e16e64bb8d82385d4f39738b08267 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
function onLoad() { | |
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 { | |
// すでに購読中 | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment