Using the FCM plugin for ionic2, I was able to successfully implement push notifications. For reference, you can check out the plugin here.
I followed the steps outlined in this Github repository, and everything is working smoothly so far. Now, my next goal is to set up my own server to allow administrators to send push notifications from their backend.
The main issue I am facing currently is figuring out how to save the device token once it is retrieved. Below is the code snippet where I am trying to get the token:
initializeApp() {
this.platform.ready().then(() => {
// Platform ready
StatusBar.styleDefault();
FCMPlugin.getToken(
function (token) {
console.log(token);
alert(token);
},
function (err) {
console.log('error retrieving token: ' + err);
}
);
I have experimented with different methods like returning the value or storing it in a variable, but I am still struggling to access the token outside of the "FCMPlugin.getToken" function. Any help on this would be greatly appreciated. Thank you!