发送Ionic 3本地通知每天特定时间 [英] Send Ionic 3 Local Notification Every day specific time
问题描述
我已从此命令添加了离子3本地通知插件。
I have added ionic 3 local notification plugin from this command.
ionic cordova plugin add cordova-plugin-local-notification
npm install --save @ionic-native/local-notifications
我添加了所有依赖项在我的构造函数上。
我的代码是:
I added all dependency on my constructor.
My Code is:
let year = new Date().getFullYear();
let month = new Date().getMonth();
let day = new Date().getDate();
let time1 = new Date(year, month, day, 10, 00, 0, 0);
let time2 = new Date(year, month, day, 12, 00, 0, 0);
this.localNotifications.schedule([
{
id: 1,
title: 'My first notification',
text: 'First notification test one',
trigger: { at: new Date(time1) },
data: {"id": 1, "name": "Mr. A"}
},
{
id: 2,
title: 'My Second notification',
text: 'Second notification on 12 pm',
trigger: { at: new Date(time2) },
data: {"id": 2, "name": "Mr. B"}
}
]);
它适用于当天应用启动。但我想在上述时间发送每天的通知。
It works fine for the current day app start. But I want to send notification every Day on above mentioned time.
注意:抱歉英文不好
推荐答案
在他们的代码库中显示(注释)你可以通过这样做来实现这个
In their codebase is shown (commented) that you could achieve this by doing this
this.localNotifications.schedule({
text: 'Delayed ILocalNotification',
trigger: {at: new Date(new Date().getTime() + 3600)},
led: 'FF0000',
sound: null});
现在,如果你必须每天同时发送通知,你可以: />
1 - 安排十分之一的通知并在每次用户打开您的应用时进行检查
2 - 每次用户打开已收到的通知时重新安排通知。
Now, if you have to send a notification every day at the same time you could either:
1 - schedule tenths of notifications and check each time a user opens your app
2 - re-schedule a notification each time the user opens up a notification already received.
这篇关于发送Ionic 3本地通知每天特定时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!