【问题标题】:FCM data not received when app is killed杀死应用程序时未收到 FCM 数据
【发布时间】:2016-09-01 14:55:17
【问题描述】:

即使应用程序被终止,我也会收到 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()

【问题讨论】:

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


    【解决方案1】:

    尝试将 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)
      }
    });
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-10
      • 2017-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多