【问题标题】:Parse Cloud Code multiple push dilemmaParse Cloud Code 多重推送困境
【发布时间】:2016-01-14 17:24:19
【问题描述】:

我的应用有基于邮政编码和频道的通知。

当用户更改邮政编码时,应用会使用新的邮政编码更新Installation

在我的beforeSaveInstallation 中,我抓取了新的 zip 和订阅频道并搜索相关通知。

然后我需要将通知作为推送发送回该安装。

两个问题:

  1. 我可以直接推送到 beforeSave 中的 Installation 对象吗:

    return Parse.Push.send({ where: request.object data: data })

还是我必须对该 objectId 进行安装查询?

  1. 我不能只推送通知对象。我需要配置数据。如果有多个通知(不太可能但可能),将多个推送发送回该安装的最佳方式是什么(假设我不想将它们全部放在一个推送中)?

我无法从for 循环发送推送。我可以这样做吗:

return notificationQuery.each().then( function(notification) { 
    //configure push from that notification
    return Parse.Push.send ... etc
})

谢谢!

【问题讨论】:

    标签: parse-platform push-notification parse-cloud-code before-save


    【解决方案1】:

    您可以基于channelswhere(查询)在parse 中发送推送通知,但不能同时使用两者。

    所以您可以使用channelzipcodeInstallation class 进行查询:

    var query = new Parse.Query(Parse.Installation);
    query.equalTo('channels', 'Indians');
    query.equalTo('zipcode', "345678");
    
    Parse.Push.send({
      where: query,
      data: {
        action: "com.example.UPDATE_STATUS"
        alert: "Ricky Vaughn was injured in last night's game!",
        name: "Vaughn",
        newsItem: "Man bites dog"
      }
    }, {
      success: function() {
        // Push was successful
      },
      error: function(error) {
        // Handle error
      }
    });
    

    希望这会有所帮助。

    【讨论】:

    • 谢谢。我在第一个问题中的意思是我可以只做{where : request.object} 甚至{where : [request.object]},因为查询只是返回一组安装,我已经有了我需要的安装。
    • 如果您已经拥有所需的安装,只需使用这些安装中的通道并将推送发送到所需的通道。
    • 我有安装,只需要推送到那个安装。我必须将查询传递给推送还是可以通过安装?不涉及任何渠道。
    • 请参阅docs,您可以使用频道或查询来发送推送。因此,在您的场景中,只需使用对 zipcode 的查询即可。
    猜你喜欢
    • 1970-01-01
    • 2015-10-25
    • 1970-01-01
    • 2014-11-20
    • 1970-01-01
    • 2016-11-12
    • 2018-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多