NativeScript FCM - txgz999/Mobile GitHub Wiki
FCM in Nativescript
- https://github.com/EddyVerbruggen/nativescript-plugin-firebase
- https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/docs/MESSAGING.md
- https://play.google.com/store/apps/details?id=org.nativescript.pluginshowcase
- https://www.nativescript.org/blog/how-to-add-firebase-analytics-to-your-nativescript-mobile-app
- https://sweetcode.io/setting-firebase-push-notification-existing-nativescript-angular/
- https://discourse.nativescript.org/t/where-is-the-console-log-output/4372/7
- register the Android package name in Firebase console (find the package name from the nativescript/id field in package.json)
- download google-services.json and save it to the App_Resources/Android folder
- run
tns plugin add nativescript-plugin-firebase
- add to src/app/app.component.ts:
import * as firebase from "nativescript-plugin-firebase";
ngOnInit(): void { firebase.init({ onPushTokenReceivedCallback: function (token) { console.log("Firebase push token: " + token); }, onMessageReceivedCallback: function (message) { console.log("Title: " + message.title); console.log("Body: " + message.body); // if your server passed a custom property called 'foo', then do this: console.log("Value of 'foo': " + message.data.foo); } }).then( instance => { console.log("firebase.init done"); }, error => { console.log(`firebase.init error: ${error}`); } ); }
- To find the registration token at any time, use code like the following, which can be bound to a button tap event:
onTap(args: EventData) { let button = args.object as Button; firebase.getCurrentPushToken().then((token: string) => { // may be null if not known yet console.log(`Current push token: ${token}`); }); }