I'm using the iOS Parse Framework. I'm creating a user like this:

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.
    }
}];

But if I use this code:

 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]);
    }


}];

this works and lists all the user names. I want that every user can get only his information and not others. how can I implement that? I tried doing the following:

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

but it won't let me, so what I basically want to do and don't know how is I don't want users to be able to fetch all the users from the 'User' table I want every user only having access to its own user object.

有帮助吗?

解决方案

Try saving the ACL after the user has already been created.

    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.
             }

    }];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top