每天在特定时间发送Ionic 3 Local Notification [英] Send Ionic 3 Local Notification every day at a specific time
问题描述
我已使用以下命令将Ionic 3本地通知插件添加到我的项目中:
I have added the Ionic 3 local notification plugin to my project using these commands:
ionic cordova plugin add cordova-plugin-local-notification
npm install --save @ionic-native/local-notifications
我在构造函数上添加了所有依赖项.
I added all dependencies on my constructor.
我的代码是:
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 a notification every day at the specified time.
我要特别是本地通知,而不是推送通知.
I want local notifications specifically, not push notifications.
推荐答案
在其代码库中显示(注释)您可以通过执行此操作来实现
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 Local Notification的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!