离子框架FCM插件

时间:2016-10-17 11:26:17

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

到目前为止,我可以通过firebase控制台(firebase)成功发送所有应用程序的通知。
问题是我无法向特定设备发送通知。

这是我在运行函数中的代码:

.run(function($ionicPlatform) {
   $ionicPlatform.ready(function() {
      FCMPlugin.getToken(
      function(token){
          alert("fire base token :)    :"+token);
      },
      function(err){
          console.log('error retrieving token: ' + err);
      }
  )

});

我得到令牌,当我使用firebase将其发送到特定设备时,它表示“令牌无效/”
哪个部分出错?我误解了什么吗?
我的项目是离子框架选项卡示例代码。

1 个答案:

答案 0 :(得分:0)

使用吹码

.run(function ($ionicPlatform, $rootScope, $state) {
$ionicPlatform.ready(function() {
    if(window.cordova) {
        FCMPlugin.onNotification(
            function(data){

                if(data.wasTapped){
                   // $state.go('message', {id:data.pageId});
                  // $location.path('app/userList');
                    console.log('onNotification tapped true');
                } else {
                    console.log("xxxxxxxxxxxx"+data.message);
                }
            },
            function(msg){
             // alert("asdf"+msg)
                console.log('onNotification callback successfully registered: ' + msg);
                FCMPlugin.getToken(
                 function(token){
                   //alert(token);
                   window.localStorage.setItem("deviceId",token)
                 },
                 function(err){
                   console.log('error retrieving token: ' + err);
                 }
               )
            },
            function(err){
             // alert("fjkjg"+err)
                console.log('Error registering onNotification callback: ' + err);
            }
        );
    }
});

})