Created
January 13, 2020 11:25
-
-
Save pmbanugo/acead6e60a11052752dc3957e26a0da1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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