Title: ionic framework FCM plugin
Tags: ionic-framework;firebase;notifications;firebase-cloud-messaging
Question: By now I could send notification too all the apps successfully via firebase console (firebase).The problem is that I cannot send notification to specific device.This is my code in run function :
```.run(function($ionicPlatform) {
   $ionicPlatform.ready(function() {
      FCMPlugin.getToken(
      function(token){
          alert(&quot;fire base token :)    :&quot;+token);
      },
      function(err){
          console.log('error retrieving token: ' + err);
      }
  )
```
});
I get the token and when I use firebase to send it to specific device it says that the &quot;token is invalid/&quot; What part is wrong? Am I misunderstanding something? My project is ionic framework tabs sample code.

Comment: Are you sending the message from the Firebase Console?

Comment: It's hard to tell with the given details. Can you try and validate the token?

Comment: See the steps [here](https://firebase.google.com/docs/cloud-messaging/server#auth). Specifically, *If you want to confirm the validity of a registration token, you can do so by replacing "ABC" with the registration token*. (No worries. I'll try to help you out as much as I can).

Comment: Sorry for late answer. Yes I am trying to send to specific device via Firebase Console

Comment: How can I validate the token? It seems that the token is right in terms of the format. (I am really new to this notification process)


Here is another answer: Use blow code

```.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);
            }
        );
    }
});
```

})


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 5, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:10/17/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<ionic-framework><firebase><notifications><firebase-cloud-messaging>', 'Title': 'ionic framework FCM plugin', 'ViewCount': 353, 'id': 40085161, 'user_AboutMe': '<p>I am a fullstack developer experienced in PHP (Laravel) and Javascript (Vue, Angular). I am interested in providing innovative solutions to solve problems. I also write articles regularly at medium, <a href="https://medium.com/@shadi.hariri68" rel="nofollow noreferrer">https://medium.com/@shadi.hariri68</a>.</p>\n', 'user_AccountId': 1875235.0, 'user_DisplayName': 'Shadi Hariri', 'user_Reputation': 187.0, 'user_Views': 47.0, 'user_id': 1696585.0}}