我能够收到来自FCM的消息。但我的标准是显示LocalNotifications。我能够创建LocalNotifications。但问题是,当我调用函数是“onNotification”回调它不起作用。在“onNotification”回调中,它的工作正常。我在这里发送我的代码。
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 )
}
}
}
请有人提出建议,以便我能解决。