我想知道在Parse Server上是否可以使用Schedule Push? (我正在使用Back4App)
这是我的云代码:
Parse.Cloud.define("pushMultiple",async (request) => {
//Getting Current Date instance
var d = new Date();
//Where I live Current Hour is 14, so setting it to 15
d.setHours(15);
//Sending push to a specific device
return Parse.Push.send({
push_time: d,
channels: [ "t1g.com"],
data: {alert: "The Giants won against the Mets 2-3."}
},{ useMasterKey: true });
});
但是该代码似乎无法正常工作。推送立即发送出去。
如果无法实现,请告诉我如何使用Cloud Job安排推送。代码段将非常有帮助。在发送完推送后,Cloud Job还会停止运行吗?
答案 0 :(得分:2)
根据this文档的setHours方法不会将您的值添加到日期中,而只是将其替换。
尝试一下:
var extraTime = 1000*60*60*15; //15 hours
var currentDate = new Date();
//since date object is just number we can add our extra time to our date.
var pushDate = currentDate + extraTime; //push date is 15 hours later than now
return Parse.Push.send({
push_time: pushDate,
channels: [ "t1g.com"],
data: {alert: "The Giants won against the Mets 2-3."}
},{ useMasterKey: true });
编辑:解析文档说,尚不支持push_time。 https://docs.parseplatform.org/parse-server/guide/#push-notifications
文档可能已过时,或者如果您使用的是back4app,则可以在其服务器上实现此功能。