【问题标题】:Add unique object to PFquery that is user将唯一对象添加到用户的 PFquery
【发布时间】:2023-03-11 11:13:02
【问题描述】:

我正在尝试将关注用户的人员列表添加到用户下标题为“关注者”的列中,该列是从发件人标签的 objectatindex 检索的。 代码如下:

-(void)followButton:(id)sender {


UIButton *senderButton = (UIButton *)sender;
NSLog(@"current Row=%ld",(long)senderButton.tag);

PFObject *object = [self.objects objectAtIndex:senderButton.tag];

if (![[object objectForKey:@"followers"]containsObject:[PFUser currentUser].objectId]) {

    [[PFUser currentUser] addUniqueObject:object.objectId forKey:@"following"];
    [[PFUser currentUser] saveInBackground];


    PFUser *otherUser = [self.objects objectAtIndex:senderButton.tag];
    NSLog(@"Followed %@", otherUser);

    [otherUser addUniqueObject:[PFUser currentUser].objectId forKey:@"followers"];
    [otherUser saveInBackground];


  // NSLog(@"Followed %@", object);



} else {

    [[PFUser currentUser] removeObject:object.objectId forKey:@"following"];
    [[PFUser currentUser] saveInBackground];

    PFUser *otherUser = [self.objects objectAtIndex:senderButton.tag];
    [otherUser removeObject:[PFUser currentUser].objectId forKey:@"followers"];
    [otherUser saveInBackground];


        }

[self.tableView reloadData];

}

由于某种原因,上面的代码只添加到当前用户的“关注”数组中。再次单击时,该对象将被删除,但没有任何反应。另外,代码

 PFUser *otherUser = [self.objects objectAtIndex:senderButton.tag];
    [otherUser removeObject:[PFUser currentUser].objectId forKey:@"followers"];
    [otherUser saveInBackground];

它什么都不做,同时它应该做的工作是添加到所选行的用户的“Followers”数组中。我究竟做错了什么?目标是获得有效的追随者/追随者行动。我正在使用 PFQueryTableViewController!

【问题讨论】:

    标签: ios parse-platform pfuser


    【解决方案1】:

    您不能从客户端修改其他用户的对象。您只能修改当前用户。修改用户为当前用户的方法是通过Parse.Cloud.useMasterKey()使用云代码中的主密钥;

    https://parse.com/questions/how-can-i-allow-a-user-to-edit-another-user

    因此,通过传递“otherUser”的用户名和要删除的 objectId 在云代码中创建一个函数

    Parse.Cloud.define("RemoveFollower", function(request, response){
    var username = request.params.username;
    var id_to_remove = request.params.objectId_passed;
    var query = new Parse.Query(Parse.User);
    query.equalTo("username", username);
    query.find({
        success: function(results){
            var u = results[0];
            //u modify the user u however you like...
            u.save();
            response.success("Success");
        },
        error: function(){
            response.error("Error");
        }
        });
    

    【讨论】:

      猜你喜欢
      • 2016-02-06
      • 2012-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多