Last active
November 2, 2020 16:23
-
-
Save Mohammad-Faisal/6a0364cb950b221fe9985191753d4f81 to your computer and use it in GitHub Desktop.
This file contains 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 firebase from 'firebase' | |
export const useFirebaseNotificationProvider = () => { | |
if ('serviceWorker' in navigator) { | |
navigator.serviceWorker | |
.register('./firebase-messaging-sw.js') | |
.then(function (registration) { | |
console.log('Registration successful, scope is:', registration.scope) | |
}) | |
.catch(function (err) { | |
console.log('Service worker registration failed, error:', err) | |
}) | |
} | |
firebase | |
.messaging() | |
.requestPermission() | |
.then(() => firebase.messaging().getToken()) | |
.then((firebaseToken) => { | |
console.log(firebaseToken) | |
}) | |
.catch((err) => { | |
console.log(err) | |
}) | |
firebase.messaging().onMessage((payload) => { | |
console.log('payload is ', payload) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment