Angulr pwa notifications not working on some android device

Discussão em 'Angular' iniciado por Gabbodrummer, Setembro 13, 2024.

  1. Gabbodrummer

    Gabbodrummer Guest

    I developed a pwa in angular that I then put on the play store.

    I use google firebase to send notifications, on some devices when you enter the app the message to accept notifications appears correctly and they work, while on others every time you open the app the message to accept to receive notifications appears and even accepting each time the notifications do not come.

    Here are some parts of my code where I set up the notification system:

    firebase-messaging-sw.js:

    const app = firebase.initializeApp(firebaseConfig);
    const messaging = firebase.messaging();

    messaging.onBackgroundMessage((payload) => {
    console.log('[firebase-messaging-sw.js] Received background message ', payload);

    const notificationTitle = payload.notification.title;
    const notificationOptions = {
    body: payload.notification.body,
    icon: 'assets/icons/icon-152x152.png'
    };
    //self.registration.showNotification(notificationTitle, notificationOptions, "tag-1");
    });


    NotificationComponent:

    ngOnInit(): void {
    this.requestPermission();
    this.listen();
    }

    requestPermission() {
    messaging.getToken({vapidKey: environment.firebaseConfig.vapidKey})
    .then((currentToken) => {
    if (currentToken) {
    console.log(currentToken);
    } else {
    console.log('No registration token available. Request permission to generate one.');
    }
    }).catch((err) => {
    console.log(err);
    });
    }

    listen() {
    messaging.onMessage((incomingMessage) => {
    console.log(incomingMessage);
    })
    }

    Continue reading...

Compartilhe esta Página