简体   繁体   中英

chrome notifications unsubscribe event

Is it possible to catch unsubscribe event ?

This is the code im using to subscribe the user to the notifications

if ('serviceWorker' in navigator) {
    navigator.serviceWorker.ready.then(function(reg) {
      reg.pushManager.subscribe({
        userVisibleOnly: true
      }).then(function(sub) {
          add_endpoint_to_db( sub ); // im adding the user deatils to my db
      }).catch(function(e) {
        if (Notification.permission === 'denied') {

        } else {

        }
      });
  });

}

In case the user chooses to manually remove the notifications

通知删除

I want to catch the action in order to remove his entry from the DB

So is it possible to catch the notifications change event ?

Your looking for the pushsubscriptionchange event

self.addEventListener('pushsubscriptionchange', function() {
  // remove the entry from DB
});

Unsubscribe is browser setting that can be done by settings tab and offline mode so you cannot get that information

But Once the user has unsubscribed (ie deleted the service worker registration), then on sending the next message you should get a failure message from the FCM API.(if you are using firebase)

So think in this way .... :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM