解析云代码后保存不起作用

时间:2013-03-03 23:42:06

标签: xcode push-notification parse-platform

嘿,我正在使用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;
                                            }


                                       });
                       });

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

  

Uncaught得到错误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”]。

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

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:1)

以下是新人(像我一样),原始问题中的代码完全相同,还有一些注释,加上接受答案的修正。目的是展示在解析云代码中需要更改的少量代码需要更改的示例。谢谢Constantin Jacob和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;
        }
    });

});