修改当前用户的ACL

时间:2014-02-19 00:47:15

标签: ios objective-c parse-platform acl

我正在使用iOS Parse Framework。我正在创建这样的用户:

PFUser *user = [PFUser user];
user.username = self.userNameTextField.text;
user.password = self.passwordTextField.text;
user.email = self.emailTextField.text;

[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    if (!error) {
        //user saved
    } else {
        NSString *errorString = [error userInfo][@"error"];
        // Show the errorString somewhere and let the user try again.
    }
}];

但是如果我使用这段代码:

 PFQuery *query = [PFUser query];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {
        // The find succeeded.
        NSLog(@"Successfully retrieved %d scores.", objects.count);
        // Do something with the found objects
        for (PFUser *user in objects) {
            NSLog(@"User:%@",user);
        }
    } else {
        // Log details of the failure
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    }


}];

这适用于并列出所有用户名。我希望每个用户只能获得他的信息,而不是其他用户。我该如何实现呢?我尝试了以下操作:

PFACL *userACL = [PFACL ACLWithUser:[PFUser currentUser]];
[userACL setPublicReadAccess:NO];
[userACL setPublicWriteAccess:NO];
user.ACL = userACL;

但它不会让我,所以我基本上想做什么,不知道我怎么不希望用户能够从'用户'表中获取所有用户我希望每个用户只有权访问自己的用户对象。

1 个答案:

答案 0 :(得分:3)

尝试在创建用户后保存ACL。

    PFUser *user = [PFUser user];
    user.username = self.userNameTextField.text;
    user.password = self.passwordTextField.text;
    user.email = self.emailTextField.text;

    [user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

        if (!error)
        {
            PFACL *userACL = [PFACL ACLWithUser:[PFUser currentUser]];
            [userACL setPublicReadAccess:NO];
            [userACL setPublicWriteAccess:NO];

            [PFUser currentUser].ACL = userACL;
            [[PFUser currentUser] saveInBackground];

             } else {
                 NSString *errorString = [error userInfo][@"error"];
                 // Show the errorString somewhere and let the user try again.
             }

    }];