Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 200 | espaco | 1 | //import firebase from 'firebase'; |
| 2 | |||
| 3 | export const inicializarFirebase = () => { |
||
| 4 | firebase.initializeApp({ |
||
| 5 | messagingSenderId: '963735578116' // troque pelo seu sender id |
||
| 6 | }); |
||
| 7 | |||
| 8 | navigator.serviceWorker |
||
| 9 | .register('https://leocardoso94.github.io/push-notification-demo/firebase-messaging-sw.js') |
||
| 10 | .then((registration) => { |
||
| 11 | firebase.messaging().useServiceWorker(registration); |
||
| 12 | }).catch(console.error); |
||
| 13 | |||
| 14 | } |
||
| 15 | |||
| 16 | export const pedirPermissaoParaReceberNotificacoes = async () => { |
||
| 17 | try { |
||
| 18 | |||
| 19 | const messaging = firebase.messaging(); |
||
| 20 | |||
| 21 | await messaging.requestPermission(); |
||
| 22 | const token = await messaging.getToken(); |
||
| 23 | console.log('token do usuário: ', token); |
||
| 24 | |||
| 25 | return token; |
||
| 26 | } catch (error) { |
||
| 27 | console.error(error); |
||
| 28 | } |
||
| 29 | } |
||
| 30 | |||
| 31 | |||
| 32 | |||
| 33 | // WEBPACK FOOTER // |
||
| 34 | // ./src/push-notification.js |