fix unregister
This commit is contained in:
parent
ac6b282fdf
commit
e275b3da94
@ -5,9 +5,10 @@ function checkServiceWorkerSupport() {
|
|||||||
|
|
||||||
async function isPushRegistered() {
|
async function isPushRegistered() {
|
||||||
checkServiceWorkerSupport();
|
checkServiceWorkerSupport();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const regs = await navigator.serviceWorker.getRegistrations();
|
const registrations = await navigator.serviceWorker.getRegistrations();
|
||||||
for (const reg of regs) {
|
for (const reg of registrations) {
|
||||||
if (!reg.pushManager) continue;
|
if (!reg.pushManager) continue;
|
||||||
|
|
||||||
const sub = await reg.pushManager.getSubscription();
|
const sub = await reg.pushManager.getSubscription();
|
||||||
@ -26,14 +27,21 @@ async function isPushRegistered() {
|
|||||||
|
|
||||||
async function unregisterPush() {
|
async function unregisterPush() {
|
||||||
checkServiceWorkerSupport();
|
checkServiceWorkerSupport();
|
||||||
const reg = await navigator.serviceWorker.ready;
|
|
||||||
const sub = await reg.pushManager.getSubscription();
|
|
||||||
|
|
||||||
if (sub) {
|
const registrations = await navigator.serviceWorker.getRegistrations();
|
||||||
await sub.unsubscribe();
|
if (!registrations || registrations.length === 0) return;
|
||||||
}
|
|
||||||
if (!window.IS_IOS) {
|
for (const reg of registrations) {
|
||||||
await reg.unregister();
|
if (!reg.pushManager) continue;
|
||||||
|
|
||||||
|
const sub = await reg.pushManager.getSubscription();
|
||||||
|
if (sub) {
|
||||||
|
await sub.unsubscribe();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!window.IS_IOS) {
|
||||||
|
await reg.unregister();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user