Skip to content

Instantly share code, notes, and snippets.

@enappd
Created June 11, 2019 07:11

Revisions

  1. enappd created this gist Jun 11, 2019.
    41 changes: 41 additions & 0 deletions home.page.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    import { Component } from '@angular/core';
    import { FCM } from '@ionic-native/fcm/ngx';
    import { Platform } from '@ionic/angular';

    @Component({
    selector: 'app-home',
    templateUrl: 'home.page.html',
    styleUrls: ['home.page.scss'],
    })
    export class HomePage {
    pushes: any = [];
    constructor(private fcm: FCM, public plt: Platform) {
    this.plt.ready()
    .then(() => {
    this.fcm.onNotification().subscribe(data => {
    if (data.wasTapped) {
    console.log("Received in background");
    } else {
    console.log("Received in foreground");
    };
    });

    this.fcm.onTokenRefresh().subscribe(token => {
    // Register your new token in your back-end if you want
    // backend.registerToken(token);
    });
    })
    }
    subscribeToTopic() {
    this.fcm.subscribeToTopic('enappd');
    }
    getToken() {
    this.fcm.getToken().then(token => {
    // Register your new token in your back-end if you want
    // backend.registerToken(token);
    });
    }
    unsubscribeFromTopic() {
    this.fcm.unsubscribeFromTopic('enappd');
    }
    }