Created
June 11, 2019 07:11
Revisions
-
enappd created this gist
Jun 11, 2019 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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'); } }