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 ?
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 (i.e. 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 .... :)
Your looking for the pushsubscriptionchange event
self.addEventListener('pushsubscriptionchange', function() {
// remove the entry from DB
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With