Skip to content

Instantly share code, notes, and snippets.

@frederikprijck
Created November 5, 2019 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frederikprijck/3d16de717044a7af6e8822c81df48e0c to your computer and use it in GitHub Desktop.
Save frederikprijck/3d16de717044a7af6e8822c81df48e0c to your computer and use it in GitHub Desktop.
import { Component, OnInit, NgZone } from "@angular/core";
const firebase = require("nativescript-plugin-firebase");
import { AppService } from "./app.service";
@Component({
selector: "ns-app",
templateUrl: "./app.component.html"
})
export class AppComponent implements OnInit {
constructor(private appService: AppService, private ngZone: NgZone) {
}
ngOnInit() {
firebase.init({
showNotifications: true,
showNotificationsWhenInForeground: true,
// Optionally pass in properties for database, authentication and cloud messaging,
// see their respective docs.
onPushTokenReceivedCallback: (token) => {
console.log('[Firebase] onPushTokenReceivedCallback:', { token });
//TODO: set the token here
this.ngZone.run(() => this.appService.setFCMToken(token));; // = token;
},
onMessageReceivedCallback: (message) => {
console.log('[Firebase] onMessageReceivedCallback:', { message });
}
}).then(
() => { console.log("firebase.init done"); },
error => {
console.log(`firebase.init error: ${error}`);
}
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment