Skip to content

Instantly share code, notes, and snippets.

@AyoAlfonso
Last active December 4, 2018 15:51
Show Gist options
  • Save AyoAlfonso/0d66be67f4701d48a9b11133f31322a9 to your computer and use it in GitHub Desktop.
Save AyoAlfonso/0d66be67f4701d48a9b11133f31322a9 to your computer and use it in GitHub Desktop.
import messaging from 'config/firebase'
export function initializePush() {
messaging
.requestPermission()
.then(() => {
return messaging.getToken();
})
.then(token => {
console.log("FCM Token:", token);
//send the token to the server to be able to send notifications in the future
sendTokenToServer(token);
})
.catch(error => {
if (error.code === "messaging/permission-blocked") {
console.log("Please Unblock Notification Request Manually");
} else {
console.log("Error Occurred", error);
}
});
messaging.onMessage(payload => {
toastr.info(payload.body, payload.title)
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment