首页 > 解决方案 > ionic 3 fcm.onNotification() 错误:找不到类

问题描述

当我执行 this.fcm.onNotification() 时出现错误“找不到类”。

我用的是安卓设备。

我遵循此文档https://ionicframework.com/docs/native/fcm/,但我不知道如何解决此问题

离子信息

cli packages: (/usr/local/lib/node_modules)

    @ionic/cli-utils  : 1.19.2
    ionic (Ionic CLI) : 3.20.0

global packages:

    cordova (Cordova CLI) : 8.0.0 

local packages:

    @ionic/app-scripts : 3.1.9
    Cordova Platforms  : android 6.4.0 ios 4.5.4
    Ionic Framework    : ionic-angular 3.9.2

System:

    ios-deploy : 1.9.2 
    Node       : v10.6.0
    npm        : 6.1.0 
    OS         : macOS High Sierra
    Xcode      : Xcode 9.4 Build version 9F1027a 

Environment Variables:

    ANDROID_HOME : not set

Misc:

    backend : pro

app.component.ts

    constructor(private fcm: FCM) {

        this.platform.ready().then(() => {

            alert('platform ready...');

            this.fcm.subscribeToTopic('marketing');

            this.fcm.getToken().then(token => {
                alert(token);
                // backend.registerToken(token);
            });

            this.fcm.onNotification().subscribe(data => {
                    if (data.wasTapped) {
                        alert("Received in background");
                    } else {
                        alert("Received in foreground");
                    }
                },
                error => alert(error)
            );

            this.fcm.onTokenRefresh().subscribe(token => {
                alert(token);
                // backend.registerToken(token);
            });
 });

插件版本

cordova-plugin-fcm 2.1.2 "FCMPlugin"

标签: androidpush-notificationionic3cordova-plugin-fcm

解决方案


推荐阅读