应用程序被杀时未收到FCM数据

时间:2016-09-01 14:55:18

标签: ionic-framework firebase firebase-cloud-messaging

即使应用程序被杀,我也会收到FCM控制台发送的通知。 这是我的客户代码:

 $ionicPlatform.ready(function() {
    FCMPlugin.onNotification(
  function(data){
    if(data.wasTapped){
      //Notification was received on device tray and tapped by the user.
      alert( JSON.stringify(data) );
    }else{
      //Notification was received in foreground. Maybe the user needs to be notified.
      alert( JSON.stringify(data) );
    }
  },
  function(msg){
    console.log('onNotification callback successfully registered: ' + msg);
  },
  function(err){
    console.log('Error registering onNotification callback: ' + err);
  }
);
    })

问题是未收到通知回叫。日志数据显示:

View not ready. SAVED NOTIFICATION: javascript:FCMPlugin.onNotificationReceived()

1 个答案:

答案 0 :(得分:0)

尝试将FCMPlugin放入

// Ionic Starter App

angular.module('starter', ['ionic', 'starter.controllers', 'ngCordovaOauth'])

.run(function ($ionicPlatform) {
$ionicPlatform.ready(function () {
  // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
  // for form inputs)
  if (window.cordova && window.cordova.plugins.Keyboard) {
    cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    cordova.plugins.Keyboard.disableScroll(true);

  }
  if (window.StatusBar) {
    // org.apache.cordova.statusbar required
    StatusBar.styleDefault();
  }

  try{
    FCMPlugin.onNotification(
      function(data){
        console.log('DATA ==>: '+data);
        if(data.wasTapped){
          //Notification was received on device tray and tapped by the user. 
          console.log('01');
          console.log( JSON.stringify(data) );
        }else{
          //Notification was received in foreground. Maybe the user needs to be notified. 
          console.log('02');
          //alert( JSON.stringify(data));
        }
      },
      function(msg){
            console.log('onNotification callback successfully registered: ' + msg);
      },
      function(err){
        console.log('Error registering onNotification callback: ' + err);
      }
    );
  }catch(e)
  {
    console.log('in login'+e)
  }
});
})