Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法在解析云代码中更改用户安装_Javascript_Android_Cloud - Fatal编程技术网

Javascript 无法在解析云代码中更改用户安装

Javascript 无法在解析云代码中更改用户安装,javascript,android,cloud,Javascript,Android,Cloud,我正在尝试使用解析云向其他用户的解析安装添加新通道。 这是解析云代码: 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"

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

  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);
      }
    });
  });
我发送的ID数组是一个包含字符串ID列表的JSONArray。 JSONArray正确获取并迭代。 但不管我试了多少次,它似乎都不起作用。
谢谢

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

此外,还有其他JavaScript SDK无法完成的操作:

  • JavaScript SDK当前不支持订阅频道以发送/接收推送通知
  • JavaScript SDK当前不支持接收推送
  • 但另一方面,您可以发送推送通知。 然后,当我开发一个Android原生应用程序时,我被迫“混合”ParseClode和“Android代码”,以完成通知推送功能

    我希望它能帮助你


    关于

    我的错误是没有以正确的方式保存频道。 在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);
    }
    });
    });
    
    Parse.Cloud.define(“subscribeToChannel”),函数(请求、响应){
    var channelName=request.params.channel;//用户将订阅的频道
    var Id=request.params.ids;//用户的Id
    var完成=真;
    变量大小=0;
    var-pased=0;
    var循环=0;
    var idStrings=“”;
    var=要求(“下划线”);
    如果(!channelName){
    响应错误(“缺少参数:通道”);
    返回;
    }
    如果(!ids){
    响应错误(“缺少参数:ids”);
    返回;
    }
    var query=newparse.query(Parse.Installation);
    var user=new Parse.user();
    var changedObjects=[];
    var pointerArray=[];
    _.每个(id、功能(id){
    push({“\u类型”:“指针”,“类名”:“\u用户”,“objectId”:id});
    });
    //需要主密钥来更新安装
    Parse.Cloud.useMasterKey();
    query.containedIn(“用户”,指针数组);
    查询.查找({
    成功:功能(安装){
    对于(var i=0;i
    事实上,我能够做到这一点,我将回答我的问题,让大家看看。嗨,哈维,你是如何计算出该设备当前的安装情况的?你是什么意思?我得到了解析支持的帮助(这是你问的吗?)我认为你必须将installationId传递给函数。。。或者,您应该更新属于此用户的所有安装(添加指向安装对象的用户指针)
    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);
    }
    });
    });