to give you an overview of what i'm doing, i have a ionic mobile application that uses firebase as its database . One of its features that im implementing is local notifications. Here are my codes
HTML CODE
<button ion-button full (click)="scheduleNotification()">schedule</button>
<button ion-button full (click)="scheduleNotification2()">schedule</button>
so this is the html code where in there a button allowing you to click or schedule a notification
TYPESCRIPT CODE
import { Component } from '@angular/core';
import { NavController, Platform} from 'ionic-angular';
import { LocalNotifications } from '@ionic-native/local-notifications';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController, private
localNotif:LocalNotifications, private platform:Platform) {
}
scheduleNotification() {
this.platform.ready().then(()=>{
this.localNotif.schedule({
title:'Attention',
text:'Rk notification',
at: new Date(new Date().getTime() + 1 * 5000),
});
});
}
scheduleNotification2() {
this.platform.ready().then(()=>{
this.localNotif.schedule({
title:'Attention',
text:'Rk notification',
at: new Date(new Date().getTime() + 1 * 5000),
});
});
}
}
so the problem here is that, when i click both buttons for the notification to pop out , it only overrides the other. so it only displays one notification. i wanted to display both without overiding. how do i do that?
2条答案
按热度按时间2admgd591#
你需要传递一个
id
给你的localNotification
,它必须是一个数字和by default it's 0,所以如果你不声明一个id,它将覆盖以前的预定通知。如果用户能够操作通知(如编辑、删除、更新),我建议将此ID保存在某个地方,以便用户能够这样做。
由于id需要是唯一的,有很多生成id的方法,因为我不知道你的用户多久会创建一次通知,我将使用最简单的生成方法,即
Math.random()
。另一个我可以给予的建议是在尽可能小的时间单位内操纵时间,总是尝试使用毫秒或秒。
希望这能有所帮助。
u7up0aaq2#
您可以使用报警控制器代替本地通知,请访问https://ionicframework.com/docs/api/components/alert/AlertController/