如何使用离子中的getToken()修复错误?

问题描述 投票:0回答:2

我正在尝试获取用户的fcm令牌并将其上传到数据库。

我按照本教程:https://www.youtube.com/watch?v=SOOjamH1bAA

这是我的功能:

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);
  }

进口:

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
  ]

当我运行我的应用程序时,我收到此错误:

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)
getToken@http://10.0.0.23:8100/build/vendor.js:64573:123
http://10.0.0.23:8100/build/main.js:1109:74
step@http://10.0.0.23:8100/build/main.js:1072:27
http://10.0.0.23:8100/build/main.js:1047:75
t@http://10.0.0.23:8100/build/polyfills.js:3:21507
http://10.0.0.23:8100/build/main.js:1043:36
handleDb@http://10.0.0.23:8100/build/main.js:271:26
onSignIn@http://10.0.0.23:8100/build/main.js:254:26

callWithDebugContext@http://10.0.0.23:8100/build/vendor.js:15783:47
dispatchEvent@http://10.0.0.23:8100/build/vendor.js:10689:36
http://10.0.0.23:8100/build/vendor.js:39326:65
onInvokeTask@http://10.0.0.23:8100/build/vendor.js:5436:43
runTask@http://10.0.0.23:8100/build/polyfills.js:3:10844
invokeTask@http://10.0.0.23:8100/build/polyfills.js:3:16801
p@http://10.0.0.23:8100/build/polyfills.js:2:27654
v@http://10.0.0.23:8100/build/polyfills.js:2:27894
angular firebase ionic-framework firebase-cloud-messaging angularfire
2个回答
0
投票

所以我真的不知道问题是什么,但运行构建然后通过Xcode在设备上安装它对我有用。


0
投票

使用cordova-plugin-fcm而不是firebase插件。点击此链接https://medium.com/@t1tan1um/fcm-integration-for-cordova-hybrid-apps-c679f5fc1988

输入命令npm install --save @ ionic-native / fcm @ 4.20.0。而不是npm install --save @ ionic-native / fcm。 fcm版本5+不适用于离子3

© www.soinside.com 2019 - 2024. All rights reserved.