Search code examples
cordovacordova-plugin-fcm

Cordova FCM plugin


I'm very new to cordova. I have installed this plugin from this page. My question is where do I put this code if I'm not using ionic?:

FCMPlugin.onTokenRefresh(function(token){ alert( token ); });

I have managed to the token on Chrome using official firebase documentation, but the same does not work on Firefox and cordova. If I put the above code in the index.html file it does work and I don't get errors whatsoever. I seen so many videos on Youtube that use ionic and they put this code in .ts file. When I started my project I did not use ionic. Do I need to use ionic for this plugin to work?

NB: my main aim is to get the token.


Solution

  • as its cordova plugin there's no need to create ionic project you can write this code in your js file on cordova platform ready function

    just like jquery document ready

    if have just created project and installed plugin sample JavaScript will be at www/js/ folder