2014-02-19 31 views
1

我正在使用iOS Parse Framework。我創建一個用戶是這樣的:修改當前用戶的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) { 
     //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; 

,但它不會讓我,所以我基本上想要做的,不知道怎麼,我不希望用戶能夠從獲取所有用戶'用戶'表我希望每個用戶只能訪問自己的用戶對象。

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

    }]; 
+0

完美!我無法在用戶創建之前創建ACL,但這只是工作。謝謝! –