Schedule Push notification on Parse

≡放荡痞女 提交于 2020-06-17 02:11:13

问题


I was wondering if Schedule Push is available on Parse Server? (I'm using Back4App)

Here is my cloud code:

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 });
});

But the code does not seem to be working. The push is sent out immediately.

And if it's not possible, please let me know how I can schedule push using a Cloud Job. A code snippet would be very helpful. Also will the Cloud Job stop running after it has completed sending the push?


回答1:


According to this document setHours method doesnt add your value to your date but just replace it.

Try this:

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 });

Edit: Parse docs says push_time is not supported yet. https://docs.parseplatform.org/parse-server/guide/#push-notifications

Docs can be outdated or if you are using back4app, they may be implemented this feature to their servers.



来源:https://stackoverflow.com/questions/61026124/schedule-push-notification-on-parse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!