I able to get message which comes from FCM. But my criteria is to show a LocalNotifications. I able to create LocalNotifications. But problem is while I call the function is "onNotification" callbacks it does not work. Out side of the "onNotification" callbacks it work. I am sending my code here.
import { Component } from '@angular/core';
import { NavController,Platform } from 'ionic-angular';
import { LocalNotifications } from '@ionic-native/local-notifications';
declare var FCMPlugin: any;
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public platform: Platform,private localNot:LocalNotifications) {
this.onNotifon()
}
btnPushClicked(message:string)
{
this.platform.ready().then(() => {
this.localNot.schedule({
text: message,
at: new Date(new Date().getTime() + 3600),
led: 'FF0000',
sound: null
});
});
}
async onNotifon()
{
try{
//this.btnPushClicked("Test Here Sucess ");//Is this area function work
await this.platform.ready();
// FCMPlugin.onNotification()
if(typeof(FCMPlugin) != 'undefined') {
//alert("INSIDE FCMPlugin");
FCMPlugin.onNotification(function(data){
alert("INSIDE onNotification data:"+ data.message);
console.log(data);
this.btnPushClicked(data.message); //Is this area function not work
})
}
else
{
alert("FCMPlugin undefined");
}
}
catch(e)
{
alert("e problem"+e )
}
}
}
Please some one suggest something so that I can solve it.