2013-03-03 141 views
1

嘿,我使用Parse作爲我的後端,我喜歡它,但我有afterSave鉤子的問題。解析雲代碼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; 
              } 


             }); 
         }); 

每次登錄控制檯告訴我:結果:

未捕獲得到了一個error112:缺少通道名稱。

我只是不明白什麼是錯的!它必須在該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」 ]。

預先感謝任何幫助:)

回答

3

的第一個參數afterSave應該是一個類名,而不是對象ID。

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

});