Ad

How To Fix An Error With GetToken() In Ionic?

I'm trying to fetch the user's fcm token and upload it to the database.

I followed this tutorial: https://www.youtube.com/watch?v=SOOjamH1bAA

This is my function:

async getToken() {

    let token;

    if(this.platform.is('android')) {
      token = await this.firebaseNative.getToken();
    }
    if (this.platform.is('ios')) {
      token = await this.firebaseNative.getToken();
      await this.firebaseNative.grantPermission();
    }

    return this.saveTokenToDb(token);
  }

imports:

import { Injectable } from '@angular/core';
import { Firebase } from '@ionic-native/firebase/ngx';
import { Platform } from "ionic-angular";
import { AngularFireDatabase } from '@angular/fire/database';
import { Device } from '@ionic-native/device';

app.module:

imports: [
   ...
    AngularFireModule.initializeApp(FIREBASE_CONFIG),
    AngularFireDatabaseModule
  ],
  bootstrap: [IonicApp],
  entryComponents: [
...
  ],
  providers: [
...
    AngularFireDatabase,
    Firebase,
    Device,
    FcmProvider
  ]

And when I run my app I get this error:

Uncaught (in promise): TypeError: Object(__WEBPACK_IMPORTED_MODULE_1__ionic_native_core__["cordova"]) is not a function. (In 'Object(__WEBPACK_IMPORTED_MODULE_1__ionic_native_core__["cordova"])(this, "getToken", {}, arguments)', 'Object(__WEBPACK_IMPORTED_MODULE_1__ionic_native_core__["cordova"])' is an instance of Object)
[email protected]://10.0.0.23:8100/build/vendor.js:64573:123
http://10.0.0.23:8100/build/main.js:1109:74
[email protected]://10.0.0.23:8100/build/main.js:1072:27
http://10.0.0.23:8100/build/main.js:1047:75
[email protected]://10.0.0.23:8100/build/polyfills.js:3:21507
http://10.0.0.23:8100/build/main.js:1043:36
[email protected]://10.0.0.23:8100/build/main.js:271:26
[email protected]://10.0.0.23:8100/build/main.js:254:26

[email protected]://10.0.0.23:8100/build/vendor.js:15783:47
[email protected]://10.0.0.23:8100/build/vendor.js:10689:36
http://10.0.0.23:8100/build/vendor.js:39326:65
[email protected]://10.0.0.23:8100/build/vendor.js:5436:43
[email protected]://10.0.0.23:8100/build/polyfills.js:3:10844
[email protected]://10.0.0.23:8100/build/polyfills.js:3:16801
[email protected]://10.0.0.23:8100/build/polyfills.js:2:27654
[email protected]://10.0.0.23:8100/build/polyfills.js:2:27894
Ad

Answer

So I don't really know what the problem was, but running a build and then install it on the device via Xcode worked for me.

Ad
source: stackoverflow.com
Ad