Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if push notifications are blocked on current website?

I am using OneSignal and want to be able to detect current subscribtion state between those three:

  • user is blocking notifications
  • not subscribed
  • subscribed

OneSignal API gives the isPushNotificationsEnabled function, but it only detects two states: pushes allowed or not.

I wonder if there's more general (outside of OneSignal API) method to detect that, at least in some browsers.

like image 376
I Hafid Avatar asked Feb 03 '17 19:02

I Hafid


1 Answers

Solution turned out to be Notification.permission, which takes three states:

  • default
  • granted
  • denied

And that's exactly what I needed.

like image 68
I Hafid Avatar answered Sep 28 '22 08:09

I Hafid