iOS-用于添加朋友的Parse.com PFRelation仅添加当前用户的关系,而不添加正在添加的朋友的关系 [英] iOS - Parse.com PFRelation for adding friends only adds the relationship for current user, not for the friend being added

查看:94
本文介绍了iOS-用于添加朋友的Parse.com PFRelation仅添加当前用户的关系,而不添加正在添加的朋友的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有一个视图控制器,用户可以在其中添加朋友.该应用程序访问用户的通讯录,并调用Parse.com后端服务器以查看是否有任何通讯录联系人已在使用该应用程序.如果找到任何对象,则将这些用户的PFObject放置在UITableView的行中.

My app has a view controller where the user can add friends. The app accesses the user's address book, and calls to the Parse.com backend server to see if any of the address book contacts are already using the app. If any are found, then I place the PFObjects for those users in the rows of my UITableView.

表中的每一行都有一个按钮.如果用户按下某行的按钮,则将执行以下代码,该代码将创建一个名为FriendsRelation的PFRelation对象,并添加已点击的特定行的PFObject:

Each row in the table has a button. If the user presses a row's button, then the following code is executed which creates a PFRelation object called friendsRelation and adds the PFObject of the specific row that has been tapped:

PFRelation *friendsRelation = [self.currentUser relationforKey:@"friendsRelation"];

    PFUser *user = [self.allUsersInParse objectAtIndex:indexPath.row];

    [friendsRelation addObject:user];

    [self.currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

        if(error) {

            NSLog(@"%@ %@", error, [error userInfo]);

        }
}];

在大多数情况下,这一切都很好.如果我在Parse中检查当前用户的行,然后单击其friendsRelation列/键中的查看关系"按钮,它将显示他们刚刚添加的正确用户的信息.

This all works great for the most part. If I check the current user's row in Parse, and click on the "View Relations" button in their friendsRelation column/key, it will display the correct user's info that they just added.

但是,如果我返回_User主类,并找到当前用户添加的朋友行,然后单击其friendsRelation列/键中的查看关系"按钮,则该行不包含刚添加他们的当前用户的用户数据.

However, if I go back to the main _User class, and find the row for the friend that was added by the current user, and click on their "View Relations" button in their friendsRelation column/key, it does not contain the user data for the current user that just added them.

因此,基本上,如果您将某人添加到您的朋友列表中,那么他们会很好地显示在您的朋友列表中,但是如果您的新朋友去查看他们的朋友列表,您将根本不在那儿.

So basically if you add someone to your friends list, they will show up on your friends list just fine, but if your new friend goes and looks at their friends list, you won't be on there at all.

我尝试通过为当前用户添加的用户添加其他PFRelation代码来创建修复程序.看到用户2:

I tried creating a fix by adding additional PFRelation code for the user being added by the current user. See user2:

  PFRelation *friendsRelation = [self.currentUser relationforKey:@"friendsRelation"];
    PFUser *user = [self.allUsersInParse objectAtIndex:indexPath.row];
    NSLog(@"USER CONTENTS ON BUTTON PRESS: %@", user);
    [friendsRelation addObject:user];

    [self.currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

        if(error) {

            NSLog(@"%@ %@", error, [error userInfo]);

        }


    PFUser *user2 = [self.allUsersInParse objectAtIndex:indexPath.row];


    PFRelation *friendsRelation2 = [user2 relationforKey:@"friendsRelation"];


    [friendsRelation2 addObject:self.currentUser];

    [user2 saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error2) {

        if(error2) {

            NSLog(@"%@ %@", error2, [error2 userInfo]);

        }


    }];

此代码在技术上是正确的,但现在允许使用.解析会向控制台显示错误,并且基本上说不允许您为未通过登录或注册进行身份验证的用户添加PFRelation.

This code is technically correct, but it is now allowed. Parse prints an error to the console and basically says that you are not allowed to add a PFRelation for a user that has not been authenticated via login or signup.

有人对我如何进行这项工作有任何想法吗?

Does anyone have any ideas on how I can make this work?

我唯一想到的是,当添加的好友登录到应用程序时,我可以查询Parse以查找数据库中包含其objectId的所有friendsRelation对象,如果找到任何对象,则可以创建一个新的PFRelation为当前登录的用户.

The only thing i have thought of is that when the added friend logs in to the app, I can query Parse for any friendsRelation objects in the database that contain their objectId, and if any are found then I can create a new PFRelation for the currently logged in user.

但是这将需要扫描整个数据库,并且看起来效率不高,随着数据库的增长,将来的修复速度将会很慢.

But this will need to scan the entire database and seems like an inefficient fix that will be slow in the future as the database grows.

感谢您的帮助.

推荐答案

如果需要修改不是当前用户的任何用户的数据,则应将CodeCloud函数与Parse.Cloud.useMasterKey();一起使用;这样会绕过所有ACL.

If you need to modify data on any user that is not the current user, you should use a CodeCloud function with Parse.Cloud.useMasterKey(); that way will bypass all ACL.

这篇关于iOS-用于添加朋友的Parse.com PFRelation仅添加当前用户的关系,而不添加正在添加的朋友的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆