Last active
December 4, 2018 15:51
-
-
Save AyoAlfonso/0d66be67f4701d48a9b11133f31322a9 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
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