If I have both a native app and a progressive web app using web push notifications powered by service worker, is there a way to prevent a user from receiving duplicate notifications if they opt in to receiving notifications from the web site and also have the app installed?
Progressive Web Applications (PWA) make native push notifications available to any website using a service worker on just about every platform and browser. The power of web app push notifications is being able to engage customers without a native app.
Android devices with 2 copies of the app installed on the device can also receive duplicate notifications. This could happen if you have a production and staging / dev app installed at the same time with different Android package names. This would result in two different player_ids and two different push tokens.
Progressive Web Apps is a trend in 2019 and web push notifications for iOS are not supported right now.
In short - there is no easy way to do this today.
There is a discussion on Chrome here on this: https://code.google.com/p/chromium/issues/detail?id=402223
The last comment from October 2015:
For now the safest minimal solution is for sites to provide an easy opt out mechanism (which we strongly recommend you do anyway!) so users can turn off notifications from one platform
Another possible heuristic based solution is to take some measure for which interface (web or native) the user most often uses (or most recently used) and only send to that. Combined with grouping these devices by rough screen size should give a pretty good approximation.
The issue is that if the user has two similar sized devices and uses native on one and web on the other then notifications will only be delivered to one, which is an edge case.
We've also been discussing building an API so sites can tell whether their corresponding native app is installed to avoid this case, but need to start discussing that with other browser vendors to see if they'd be supportive.
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