Tuesday, 7 August 2018

Ionic 2 - firebase plugin - not able to get phone's toke

I'm using this plugin: https://github.com/arnesson/cordova-plugin-firebase I have a button on the home.html that calls a test() function in home.ts

public test(): void {
    // wrap in the platform.ready && platform.is('cordova')
    this.fcm.getToken()
      .then((token: any) => {
        console.log("token: ", token);
      });
    this.fcm.onTokenRefresh()
      .subscribe((token: any) => {
        console.log("token onTokenRefresh: ", token);
      });
  }

By the time I am at the home screen, everything should be initialized and I should be able to get the token from getToken() function. But I am getting token: undefined in my console.log. I am not getting any errors, the log is clean, i.e. no errors are being generated regarding this particular plugin.


Update 1:

import { Firebase } from '@ionic-native/firebase';
  constructor(public navCtrl: NavController
    , public fcm: Firebase) {


Update 2: Tried like this: cordova plugin add https://github.com/arnesson/cordova-plugin-firebase --variable ANDROID_VERSION=7.1.0 --save But its still null.

private void getToken(final CallbackContext callbackContext) {
    cordova.getThreadPool().execute(new Runnable() {
        public void run() {
            try {
                String token = FirebaseInstanceId.getInstance().getToken();
                System.out.println("token: " + token); // null....
                callbackContext.success(token);
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }
        }
    });
}

Above method isn't getting the token. So it seems this is not a cordova issue?



from Ionic 2 - firebase plugin - not able to get phone's toke

No comments:

Post a Comment