cordova-plugin-fcm-with-dependecy-updated icon indicating copy to clipboard operation
cordova-plugin-fcm-with-dependecy-updated copied to clipboard

Getting TypeError: Cannot read property 'getToken' of undefined for ionic 3 app.

Open Sagar-Khenat opened this issue 5 years ago • 4 comments

Hi @andrehtissot , I have been using the latest version of your plugin for our android app ( Version 7.6.0 ) . I used the similar method specified in readme file for importing the plugin: import { FCM } from "cordova-plugin-fcm-with-dependecy-updated/ionic/v4";

constructor( private fcm: FCM ) {

}

And my method call was: async getToken() { var token, permission; console.log('Inside getToken method:::'); if (this.platform.is('android')) {
token = await this.fcm.getToken().then( fcm_token => { console.log(fcm_token); });
} console.log("getToken :: ", token); this.localStorage.setObj('pushToken',token);

    if(token){
         // If it's already defined, it'll be sent right away
         console.log('Token is present, allow send push notification api::: ');

    }

}

After building and running on my device, I am getting error message as TypeError: Cannot read property 'getToken' of undefined. My projects specifications include: "cordova": "^9.0.0", "cordova-android": "9.0.0", and I have built this project using targetsdkversion as 29, which is now required for play store. Please let me know if I should use current version or previous released versions and how should I call the getToken() method. Any kind of help will be really helpful as the cordova-plugin-firebase does not work for cordova-android 9.

Sagar-Khenat avatar Nov 30 '20 09:11 Sagar-Khenat

I was getting this same error so I decided to uninstall and reinstall FCM. When you did did you notice this error:

Installing "cordova-plugin-fcm-with-dependecy-updated" for android Plugin doesn't support this project's cordova version. cordova: 8.1.1, failed version requirement: >=9.0.0 Skipping 'cordova-plugin-fcm-with-dependecy-updated' for android Installing "cordova-plugin-fcm-with-dependecy-updated" for ios Plugin doesn't support this project's cordova version. cordova: 8.1.1, failed version requirement: >=9.0.0 Skipping 'cordova-plugin-fcm-with-dependecy-updated' for ios Adding cordova-plugin-fcm-with-dependecy-updated to package.json

DuaneQ avatar Dec 06 '20 23:12 DuaneQ

You forgot platform ready declare platform in the constructor

this.platform.ready().then(() => {
	this.fcm.getToken().then(token => {
		// Save token
	})
	.catch(e => console.log('ErrorGetTocken', e))
})
.catch(e => console.log('ErrorInitFCM', e))

RidClick avatar Feb 02 '21 14:02 RidClick

I was getting this same error so I decided to uninstall and reinstall FCM. When you did did you notice this error:

Installing "cordova-plugin-fcm-with-dependecy-updated" for android Plugin doesn't support this project's cordova version. cordova: 8.1.1, failed version requirement: >=9.0.0 Skipping 'cordova-plugin-fcm-with-dependecy-updated' for android Installing "cordova-plugin-fcm-with-dependecy-updated" for ios Plugin doesn't support this project's cordova version. cordova: 8.1.1, failed version requirement: >=9.0.0 Skipping 'cordova-plugin-fcm-with-dependecy-updated' for ios Adding cordova-plugin-fcm-with-dependecy-updated to package.json

Please update the plugin version. The minimum cordova version was lowered to 8.1.0.

andrehtissot avatar Feb 03 '21 19:02 andrehtissot

I'm facing the same error @Sagar-Khenat did you resolved?

HVHMobileDeveloper avatar Aug 10 '21 10:08 HVHMobileDeveloper