在 Parse 上安排推送通知 [英] Schedule Push notification on Parse

查看:54
本文介绍了在 Parse 上安排推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 Parse Server 上是否可以使用 Schedule Push?(我正在使用 Back4App)

I was wondering if Schedule Push is available on Parse Server? (I'm using 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 });
});

但是代码似乎不起作用.推送会立即发出.

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?

推荐答案

根据 this 文档 setHours 方法不会将您的值添加到您的日期,而只是替换它.

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

试试这个:

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/#推送通知

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

文档可能已过时,或者如果您使用的是 back4app,他们可能会在其服务器上实现此功能.

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

这篇关于在 Parse 上安排推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆