【发布时间】:2017-05-15 05:55:39
【问题描述】:
我想使用 REST 向我的 android 和 ios 应用程序发送通知 Node.js 的 API?
我知道可以通过 chrone 方法完成,但我不知道如何设置 该系统,以便我可以随时向我的应用程序用户发送推送通知 我想要(在一定的时间间隔之后)。
【问题讨论】:
标签: android iphone node.js push-notification cron
我想使用 REST 向我的 android 和 ios 应用程序发送通知 Node.js 的 API?
我知道可以通过 chrone 方法完成,但我不知道如何设置 该系统,以便我可以随时向我的应用程序用户发送推送通知 我想要(在一定的时间间隔之后)。
【问题讨论】:
标签: android iphone node.js push-notification cron
/* 你可以使用 node-cron 模块。 node-cron 模块是用于 node 的纯 JavaScript 中的微型任务调度程序。该模块允许您在 node 中调度任务。 */
var cron = require('node-cron');
cron.schedule('1,2,4,5 * * * *', function() {
console.log('running every minute 1, 2, 4 and 5);
});
/* 上面的示例将每 1、2、4、5 分钟运行一次回调函数。您还可以提供范围,例如每 3 分钟持续时间 1-3。在此处输入代码 */
【讨论】:
你可以在纯 JavaScript 中使用setInterval 方法
setInterval(function () {
//Call to method which will send notification
// If you have specific endpoint then call to that endpoint
}, 3000);
对于cron 工作,还有许多npm 包可用。
【讨论】: