Created
June 11, 2019 07:11
Ionic 4 Firebase push example
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 characters
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'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment