【问题标题】:parse.com Push Notifications with advanced Targeting具有高级定位功能的 parse.com 推送通知
【发布时间】:2014-05-28 18:32:51
【问题描述】:

我正在尝试使用parse.com 服务从云代码(后台作业)实现高级推送目标。我已将日期添加为 Installation 对象中的字段。

如果我只有一个条件,即天等于 1,我使用以下 sn-p 使其工作

var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.equalTo("day",1);

Parse.Push.send({
      where: pushQuery,
      data: {
      "content-available" : "1",
      alert : "Message day 1!",
      sound : "default"
   }}, {
       success: function() {
   // Push was successful
   },
       error: function(error) {
       // Handle error
   }}).then(function() {
       // Set the job's success status
       status.success("Job finished successfully.");
   }, function(error) {
       // Set the job's error status
       status.error("Uh oh, something went wrong.");
   });

参考:Push Notification Java Script guide

我的下一步是向 20 个查询(0

【问题讨论】:

    标签: javascript push-notification apple-push-notifications parse-platform


    【解决方案1】:

    我使用Parse.Promise.when(promises)解决了我的问题

    Promises 有点神奇,因为它们可以让你在不嵌套的情况下将它们链接起来。如果一个 Promise 的回调返回一个新的 Promise,那么第一个 Promise 直到第二个 Promise 才被解决。这使您可以执行多个操作,而不会产生您会通过回调获得的金字塔代码。

    function scheduleWordsForDay(day)
    {
        var pushQuery = new Parse.Query(Parse.Installation);
        pushQuery.equalTo("day",day);
        pushQuery.exists("deviceToken");
    
        var promise = new Parse.Promise();
    
        Parse.Push.send({
              where: pushQuery,
              data: {
              alert : "word" + day
        }}, { success: function() {
              // Push was successful
            },
              error: function(error) {
    
            }}).then (function(result){
              //Marks this promise as fulfilled, 
              //firing any callbacks waiting on it.
              promise.resolve(result);
            }, function(error) {
              //Marks this promise as fulfilled, 
              //firing any callbacks waiting on it.
              promise.reject(error);
            });
        return promise;
    }
    
    Parse.Cloud.job("scheduleWordNotification", function(request, status)
    {
      var promiseArray = [];
    
        for (var i = 0; i < 100; i++) {
            var promise = scheduleWordsForDay(i);
            promiseArray.push(promise);
      }
      //Returns a new promise that is 
      //fulfilled when all of the input promises are resolved.          
      Parse.Promise.when(promiseArray).then(function(result) {
         console.log("success promise!!")
         status.success("success promise!!");
      }, function(error) {
         console.error("Promise Error: " + error.message);
         status.error(error);
      });
    });
    

    【讨论】:

      猜你喜欢
      • 2015-12-19
      • 2021-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-22
      • 1970-01-01
      相关资源
      最近更新 更多