Created
November 5, 2019 11:13
-
-
Save frederikprijck/3d16de717044a7af6e8822c81df48e0c to your computer and use it in GitHub Desktop.
This file contains hidden or 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, 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