我正在使用ionic-native的LocalNotifications每次下午6点触发本地通知。但是,当下午6点时,我会收到大量垃圾邮件通知。 我只想在下午6点接收一个通知,而不是每次下午6点接收。
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Platform, AlertController } from '@ionic/angular';
import { LocalNotifications } from '@ionic-native/local-notifications/ngx';
@Component({
selector: 'app-mypage',
templateUrl: './mypage.page.html',
styleUrls: ['./mypage.page.scss'],
})
export class MyPagePage implements OnInit {
constructor(private router: Router, private plt: Platform, private localNotifications: LocalNotifications, private alertCtrl: AlertController) {
this.initPlatform();
}
ngOnInit() {
}
private initPlatform() {
this.plt.ready().then(() => {
this.localNotifications.on('click').subscribe(res => {
let msg = res.data ? res.data.mydata : '';
this.showAlert(res.title, res.text, msg);
});
this.localNotifications.on('trigger').subscribe(res => {
let msg = res.data ? res.data.mydata : '';
this.showAlert(res.title, res.text, msg);
});
});
this.scheduleNotification();
}
private scheduleNotification() {
this.localNotifications.schedule({
id: 1,
title: 'Session terminée',
text: 'Donnez votre avis',
data: { mydata: 'Donnez votre avis' },
trigger: { every: { hour: 18, minute: 0 } },
foreground: true
});
}
private showAlert(header, sub, msg) {
this.alertCtrl.create({
header: header,
subHeader: sub,
message: msg,
buttons: ['Ok']
}).then(alert => alert.present());
}
}