我想在通知来自FCM服务器时显示本地通知

时间:2017-09-14 10:39:19

标签: ionic3

我能够收到来自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 )
    }

   }

  }

Data Comes From FCM

Error show while execute btnPushClicked()

请有人提出建议,以便我能解决。

0 个答案:

没有答案