【发布时间】: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