我是第一次使用 ionic 2 本地通知。我遵循了这个YouTube教程。
当我在 Xcode 中测试我的应用程序时,我在下面收到一条警告消息,并且通知消息没有显示......不知道为什么。
瓦恩:未知属性:在
我已经安装了
Ionic Cordova插件添加de.appplant.cordova.plugin.local-notification
npm install --save @ionic-native/local-notification
并将插件作为提供程序添加到 src/app/app.module.ts 中
我有以下代码:
首页.html:
<button ion-button (click)=myNotifications()>Test</button>
app.module.ts
import { Component } from '@angular/core';
import { NavController, Platform, ActionSheetController, AlertController } from 'ionic-angular';
import { ScreenOrientation } from '@ionic-native/screen-orientation';
import { LocalNotifications } from '@ionic-native/local-notifications';
export class HomePage {
constructor(public navCtrl: NavController,
public platform: Platform,
private screenOrientation: ScreenOrientation,
private localNotifications: LocalNotifications,
public alertCtrl: AlertController ) {
this.platform.ready().then((ready) =>{
this.localNotifications.on('click', (notification, state) => {
let json = JSON.parse(notification.data);
let alert = this.alertCtrl.create({
title: notification.title,
message: json.fullMsq
});
alert.present();
});
});
}
myNotifications() {
this.localNotifications.schedule({
id: 1,
title: 'ABC Meeting Notification',
text: 'ABC Meeting will start in 20 mins',
at: new Date(new Date().getTime() + 20*60*1000),
data: { fullMsq: 'this is the full notification message' }
})
}
}
参考通知演示:https://github.com/husainsr/Ionic3_Notification愿它证明对你有帮助。