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?
My google-services.json was wrong. I think I had created a new project but I must have not replaced the google-services.json with the new/current project's.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With