我正在尝试使用解析云向其他用户的解析安装添加新通道。 这是Parse Cloud Code:

  Parse.Cloud.define("subscribeToChannel", function(request, response) {
  var channelName = request.params.channel;
  var ids = request.params.ids;//this is an array of ids to change
  var _ = require("underscore");
  _.each(ids, function(id) {
  // Create a Pointer to this user based on their object id
    var user = new Parse.User();
    user.id = id;
    // Need the Master Key to update Installations
    Parse.Cloud.useMasterKey(); 
    // A user might have more than one Installation
    var query = new Parse.Query(Parse.Installation);
    query.equalTo("User", user); // Match Installations with a pointer to this User
    query.find({
      success: function(installations){
    for (var i = 0; i < installations.length; i++){
      // Add the channel to all the installations for this user
      installations[i].addUnique("channels", channelName);
    }
    // Save all the installations
    Parse.Object.saveAll(installations, {
      success: function(installations) {
      },
      error: function(error) {
        // An error occurred while saving one of the objects.
        console.error(error);
      }
    });
      },
      error: function(error) {
    console.error(error);
      }
    });
  });

这就是我为每个用户设置第一个安装的方法:

ParseInstallation inst = ParseInstallation.getCurrentInstallation();
inst.put("User", ParseUser.getCurrentUser());

我发送的id数组是一个JSONArray,它包含一个字符串ID列表。 JSONArray正确获取并迭代。 但不管我试过多少次,它似乎都没有用。 谢谢!

===============>>#1 票数:2 已采纳

我的错误是我没有以正确的方式保存频道。 经过长时间与Parse的开发团队交谈后,我能够实现这一目标。 这是代码:

Parse.Cloud.define("subscribeToChannel", function(request, response) {
var channelName = request.params.channel; //Channel the user will be subscribed to
var ids = request.params.ids; //Id of the users
var completed = true;
var size = 0;
var pased = 0;
var loops = 0;
var idStrings = "";
var _ = require("underscore");
if (!channelName) {
response.error("Missing parameter: channel");
return;
}
if (!ids) {
response.error("Missing parameter: ids");
return;
}
var query = new Parse.Query(Parse.Installation);
var user = new Parse.User();
var changedObjects = [];
var pointerArray = [];
_.each(ids, function(id){
pointerArray.push({"__type":"Pointer","className":"_User","objectId":id});
});

// Need the Master Key to update Installations
Parse.Cloud.useMasterKey();
query.containedIn("User",pointerArray);
query.find({
success: function(installations){
for (var i = 0; i < installations.length; i++){
// Add the channel to all the installations for this user
installations[i].addUnique("channels", channelName); //Add the channel to the installation
changedObjects.push(installations[i]); //Add the installation to be saved later on!
}

//Saving all the installations
Parse.Object.saveAll(changedObjects, { 
success: function(installations) {
response.success();
},
error: function(error) {
// An error occurred while saving one of the objects.
response.error(error);
}
});
},
error: function(error) {
response.error(error);
}
});
});

===============>>#2 票数:1

我刚刚找到了你的问题,因为我正在尝试使用CloudCode进行相同的操作,但似乎不可能,至少目前是这样。 根据Parse团队的说法:“JavaScript SDK目前不支持修改安装对象。请查看iOS,Android或REST Push指南”。 下面是链接:

parse.com/docs/push_guide#setup/JavaScript

此外,还有JavaScript SDK无法执行的其他操作:

  1. JavaScript SDK目前不支持订阅频道以发送/接收推送通知
  2. JavaScript SDK目前不支持接收推送

但另一方面,您可以发送推送通知。 然后,当我开发Android原生应用程序时,我被迫“混合”ParseClode和“Android代码”以完成通知推送功能。

我希望它会对你有所帮助

问候

  ask by Javi translate from so

未解决问题?本站智能推荐: