1

嘿,我使用 Parse 作为后端,我喜欢它,但 afterSave 钩子有问题。

这是我正在使用的代码:

Parse.Cloud.afterSave ("JGZwoelf",function (request) {

                       Parse.Push.send({
                                       //Selecting the Channel
                                       channels: [ request.object.get('JGZwoelfPush') ],

                                            data: {
                                            //Selecting the Key inside the Class
                                            alert: request.object.get('AusfallInfo')

                                            }
                                       }, {
                                            success: function () {
                                            //Push was send successfully
                                            },

                                            error: function (error) {
                                            //Handle error
                                            throw "Got an error" + error.code + " : " + error.message;
                                            }


                                       });
                       });

每次日志控制台告诉我:结果:

未捕获 出现错误 112:缺少频道名称。

我只是不明白出了什么问题!它必须在那个 JavaScript 代码中。如果我手动输入推送通知一切正常:/

编辑: Parse.Push.send 部分应如下所示:

Parse.Push.send ({
        //Selecting the already existing Push Channel
        channels: ["JGAchtPush"], //This has to be the name of your push channel!!
        data: {
            //Selecting the Key inside the Class
            alert: request.object.get ("AusfallInfo")
        }
    }, {
        success: function () {
            //Push was sent successfully
            //nothing was loged
        },
        error: function (error) {
            throw "Got and error" + error.code + " : " + error.message;
        }
    });

频道名称需要类似于 ["exampleChannel"]。

提前感谢任何给定的帮助:)

4

2 回答 2

3

afterSave 的第一个参数应该是类名,而不是 objectId。

于 2013-03-04T18:07:03.147 回答
1

以下是针对新人(比如我)的,它与原始问题中的代码完全相同,再加上一些评论,以及对已接受答案的更正。目的是展示需要更改几段代码才能在您的解析云代码中工作的示例。谢谢康斯坦丁雅各布和 bklimt。

Parse.Cloud.afterSave ("UserVideoMessage",function (request) { // name of my parse class is "UserVideoMessage"

    Parse.Push.send ({
        //Selecting the already existing Push Channel
        channels: ["admin"], //This has to be the name of your push channel!!
        data: {
            //Selecting the Key inside the Class, this will be the content of the push notification
            alert: request.object.get ("from")
        }
    }, {
        success: function () {
            //Push was sent successfully
            //nothing was loged
        },
        error: function (error) {
            throw "Got and error" + error.code + " : " + error.message;
        }
    });

});
于 2014-09-24T05:27:29.103 回答