Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

236
Visualizações
How to push notification with firebase FCM to all users of my App with Ionic?

I need to notify all users with latest news , i did only notification method with token of user but notification shown only on the device of this user ,i need to notify all users of my application , this code is for send notification by token of user only , how to send to group of users or all users , thanks for help

app.component.ts :

    import { Component, OnInit } from '@angular/core';
import { CrudService } from './crud.service';
import { Platform } from '@ionic/angular';

import { StatusBar } from '@ionic-native/status-bar/ngx';
import { Router } from '@angular/router';
import {
  ActionPerformed,
  PushNotificationSchema,
  PushNotifications,
  Token,
} from '@capacitor/push-notifications';

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss'],
})
export class AppComponent implements OnInit  {
  constructor(public crud: CrudService ,  private platform: Platform,
    private statusBar: StatusBar,
    public router:Router){
      this.initializeApp();
    crud.databaseConn();
    crud.getUsersList();
    }


    initializeApp() {

      this.platform.ready().then(() => {
        this.statusBar.styleDefault();
        this.router.navigateByUrl('splash');
      });
    }


    ngOnInit() {
      console.log('Initializing HomePage');
  
      // Request permission to use push notifications
      // iOS will prompt user and return if they granted permission or not
      // Android will just grant without prompting
      PushNotifications.requestPermissions().then(result => {
        if (result.receive === 'granted') {
          // Register with Apple / Google to receive push via APNS/FCM
          PushNotifications.register();
        } else {
          // Show some error
        }
        
      });
  
    PushNotifications.addListener('registration', (token: Token) => {
        alert('Push registration success, token: ' + token.value);
        console.log("token"+token.value)
      });
  
      PushNotifications.addListener('registrationError', (error: any) => {
        alert('Error on registration: ' + JSON.stringify(error));
      });
  
      PushNotifications.addListener(
        'pushNotificationReceived',
        (notification: PushNotificationSchema) => {
          var audio = new Audio("assets/bip_bip.mp3");
          audio.play();
          alert('Push received: ' + JSON.stringify(notification));
        },
      );
  
      PushNotifications.addListener(
        'pushNotificationActionPerformed',
        (notification: ActionPerformed) => {
          alert('Push action performed: ' + JSON.stringify(notification));
        },
      );
    }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

To send push notifications to multiple devices over FCM you need to use topics and subscribe certain group of users to the same topic. For example:

import { PushNotifications } from "@capacitor/push-notifications";
import { FCM } from "@capacitor-community/fcm";
Import { Capacitor } from “@capacitor/core”;

// set up base push notifications with Capacitor
await PushNotifications.requestPermissions();
await PushNotifications.register();

let topic;
if (Capacitor.getPlatform() === ‘ios’) {
  topic = ‘apple’
} else if (Capacitor.getPlatform() === ‘android’) {
  topic = ‘google’
}


// set up Firebase Cloud Messaging topics
FCM.subscribeTo({ topic  })
  .then(r => console.log(`subscribed to topic “${topic}”`))
  .catch(err => console.log(err));

Then on FCM console you can test it out with sending notification to those topics: Like shown on this image

If you want to unsubscribe from topic you just use FCM.unsubscribeFrom()..

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda