【问题标题】:FCMPlugin is not Defined in home.tsFCMPlugin 未在 home.ts 中定义
【发布时间】:2018-01-19 08:46:21
【问题描述】:

我正在尝试使用 Firebase 和 Ionic 3 发送推送通知。我已经通过我的 cmd 在我的项目中导入了 FCMPlugin。当我在 firebase 中创建新消息并尝试结束时,我没有收到任何内容,我在项目中运行控制台日志,它给了我以下错误“未定义 FCMPlugin”。

我在home.ts中声明了Plugin,但还是报这个错,我的home.ts如下:

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import {AlertController} from 'ionic-angular';
declare var FCMPlugin: any; // <---- this is the magic line

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(private alert:AlertController, private platform:Platform) {
this.onNotification();
  }


 async  onNotification(){

try {

await this.platform.ready();
 FCMPlugin.onNotification((data)=>{

    this.alert.create({


   message: data.message

    }).present(); 

},(error) => console.error(error));
}
catch (e) {
console.error(e);

}

 }

}

谁能给我一些指导,因为我对离子很陌生? 感谢问候

【问题讨论】:

  • 你是在模拟器还是设备上尝试这个

标签: firebase ionic-framework firebase-cloud-messaging ionic3


【解决方案1】:

尝试在 if 块中使用 FCM onNotification 方法,这样无论何时在浏览器上使用它或在初始化之前调用 FCM 时,它都不会引发错误:

if (typeof FCMPlugin != 'undefined') {
  FCMPlugin.onNotification((data)=>{})
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-09
    • 2019-02-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多