2015-01-14 133 views
0

我正在嘗試向特定用戶的安裝發送推送通知。無法通過解析發送推送通知通過解析CloudCode

在用戶類中,我有一個指向安裝實例的指針。這是我的代碼:

Parse.Cloud.beforeSave("Notification", function(request, response) { 
    var user; 

    if (!request.object.get("reciever")) { 
     response.error("Please include a user"); 
    } else { 
     user = request.object.get("reciever"); 
    } 

     var message = request.object.get("message"); 

     var query = new Parse.Query(Parse.User); 
     query.include("installation"); 
     query.equalTo("objectID", user.get("objectID")); 
     query.find({ 
       success: function(result) { 
         var obj = result[0]; 
       var intst = obj.get("installation"); 
        console.log(intst); 

         Parse.Push.send({ 
          where: intst, 
          data: { 
          alert: message 
          } 
         }, { 
          success: function() { 
          console.log("Push was successful"); 
           response.success(); 
          }, 
          error: function(error) { 
          console.error(error); 
         response.error(error); 
          } 
         }); 
       }, 
       error: function(error) { 
       response.error(error); 
       } 
     }); 
}); 

從查看我的日誌,安裝實例已正確接收。發送時,出現以下錯誤:

Failed to create new object, with error code: {"code":115,"message":"Missing the push channels."}

我在做什麼錯?

回答

0

解析文檔specifys以此爲發送使用Javascript

Parse.Push.send({ 
    channels: [ "Giants", "Mets" ], 
    data: { alert: "The Giants won against the Mets 2-3." } 
}, { 
    success: function() {  
     // Push was successful 
    }, error: function(error) { 
     // Handle error 
    } 
}); 

你所缺少的是推notificatons一個例子「頻道:‘巨人’,‘大都會’]」這一推notifcation的部分。如果你在解析中進入你的安裝表,你會注意到有一個Channels欄,這就是定義發送給誰的人。在這個例子中,推送給任何已經註冊了頻道'巨人'和'大都會'的人。