解析云代码推送通知

时间:2015-08-28 01:04:40

标签: ios parse-platform push-notification

我有一个Class“Storybaord”,有两个发送推送通知的实例。

  1. 用户喜欢帖子 - SqlCommand

  2. 用户对帖子发表评论 - [postObject addUniqueObject: [PFUser currentUser] forKey:@"likes"];

  3. 在我的云代码中,我使用[postObject addUniqueObject: self.comment forKey:@"comments"];但我不确定如何区分这两者,并且还确定它们是否发生,因为还有其他情况需要保存Parse.Cloud.afterSave而不需要发送推送。

    Cloud Code:

    postObject

1 个答案:

答案 0 :(得分:1)

如果您坚持通过云代码发送推送,那么您所要做的就是设置一个客户端的条件语句并采取相应的行动,这样您可以根据自己的需要选择发送或不发送,因为您提到了一些关于有选择地发送推送:

if (self.likeButton.isSelected) {
    [PFCloud callFunctionInBackground:@"alertAuthor" withParameters:@{@"message", [NSString stringWithFormat:@"%@ liked your post!", [PFUser currentUser].username]}
} 

if (self.commentEntered) {
    [PFCloud callFunctionInBackground:@"alertAuthor" withParameters:@{@"message", [NSString stringWithFormat:@"%@ commented on your post!", [PFUser currentUser].username]}
}

只需通过云代码使用参数发送推送:

Parse.Cloud.define("alertAuthor", function(request,response){
  var query = new Parse.Query(Parse.User);
  var message = request.params.message;
  query.equalTo('username', 'postUser');

  Parse.Push.send({
    where: query,
    data : { 
      alert: message,
      badge: "Increment",
      sound: "",
    }
    }, {
    success: function() {
    //Success
    },
    error: function(error) {
    //Oops
    }
  });
});
相关问题