0

I want to send notification in ionic app using FCM but first I want to get device token using FCM. I have already tried below method to get device token.working. But I want to get device token using FCM. Anyone knows how to get, kindly help.

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

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    var push = new Ionic.Push({
      "debug": true
    });

    push.register(function(token) {
      console.log("My Device token:",token.token);
      push.saveToken(token);  // persist the token in the Ionic Platform
    });
  });
})
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
umer safeer
  • 69
  • 2
  • 16
  • hmm you're probably looking at very old documents. check this out http://stackoverflow.com/questions/37653251/firebase-cloud-messaging-with-ionic-app/39262282#39262282 this if you wanna send push notification to all the device who downloaded the app – JC Borlagdan Nov 18 '16 at 08:59

1 Answers1

0

With this plugin : https://github.com/fechanique/cordova-plugin-fcm you can access your Device token this way :

FCMPlugin.getToken(
  function(token){
    alert(token);
  },
  function(err){
    console.log('error retrieving token: ' + err);
  }
);

Everything needed to use Firebase is in this plugin.

Have fun :)

nkayou
  • 271
  • 2
  • 9