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