dev #12425
This commit is contained in:
parent
9428c3638b
commit
8659ba1fc2
@ -64,6 +64,7 @@ export class MainComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
requestPermission() {
|
requestPermission() {
|
||||||
|
console.log('####: ')
|
||||||
this.messagingService.requestPermission()
|
this.messagingService.requestPermission()
|
||||||
this.messagingService.receiveMessage()
|
this.messagingService.receiveMessage()
|
||||||
this.message = this.messagingService.currentMessage
|
this.message = this.messagingService.currentMessage
|
||||||
|
|||||||
@ -52,19 +52,32 @@ export class MessagingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
requestPermission() {
|
requestPermission() {
|
||||||
this.angularFireMessaging.requestToken.subscribe({
|
try {
|
||||||
next: (token) => {
|
console.log('1');
|
||||||
this.updateToken(token);
|
|
||||||
console.log(token);
|
this.angularFireMessaging.getToken.subscribe({
|
||||||
},
|
next: (val) => {
|
||||||
error: (e) => console.error(e),
|
console.log('VAL: ', val)
|
||||||
});
|
}
|
||||||
|
})
|
||||||
|
this.angularFireMessaging.requestToken.subscribe({
|
||||||
|
next: (token) => {
|
||||||
|
console.log('#: ')
|
||||||
|
this.updateToken(token);
|
||||||
|
console.log('####TOKEN: ', token);
|
||||||
|
},
|
||||||
|
error: (e) => console.error(e),
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* hook method when new notification received in foreground
|
* hook method when new notification received in foreground
|
||||||
*/
|
*/
|
||||||
receiveMessage() {
|
receiveMessage() {
|
||||||
|
console.log('#REC')
|
||||||
this.angularFireMessaging.messages.subscribe((payload: any) => {
|
this.angularFireMessaging.messages.subscribe((payload: any) => {
|
||||||
console.log('new message received. ', payload);
|
console.log('new message received. ', payload);
|
||||||
this.currentMessage.next(payload);
|
this.currentMessage.next(payload);
|
||||||
|
|||||||
@ -1,13 +0,0 @@
|
|||||||
importScripts('https://www.gstatic.com/firebasejs/3.6.8/firebase-app.js');
|
|
||||||
importScripts('https://www.gstatic.com/firebasejs/3.6.8/firebase-messaging.js');
|
|
||||||
|
|
||||||
firebase.initializeApp({
|
|
||||||
apiKey: "AIzaSyCujHg9GtN8Uxi-JcCN8zggvXlfNQRKc04",
|
|
||||||
authDomain: "push-notification-test2-56dac.firebaseapp.com",
|
|
||||||
projectId: "push-notification-test2-56dac",
|
|
||||||
storageBucket: "push-notification-test2-56dac.appspot.com",
|
|
||||||
messagingSenderId: "1004369687552",
|
|
||||||
appId: "1:1004369687552:web:a6cc20625e05520a37d4e5"
|
|
||||||
});
|
|
||||||
|
|
||||||
const messaging = firebase.messaging();
|
|
||||||
Loading…
Reference in New Issue
Block a user