Skip to content

Instantly share code, notes, and snippets.

@pmbanugo
Created January 13, 2020 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmbanugo/acead6e60a11052752dc3957e26a0da1 to your computer and use it in GitHub Desktop.
Save pmbanugo/acead6e60a11052752dc3957e26a0da1 to your computer and use it in GitHub Desktop.
componentDidMount() {
this.askNotificationPermission();
}
askNotificationPermission = async () => {
// check if the browser supports notifications
if ("Notification" in window) {
if (this.checkNotificationPromise()) {
const permission = await Notification.requestPermission();
this.handlePermission(permission);
} else {
Notification.requestPermission(permission => {
this.handlePermission(permission);
});
}
} else {
console.log("This browser does not support notifications.");
}
};
handlePermission = permission => {
if (!("permission" in Notification)) {
Notification.permission = permission;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment