简体   繁体   English

Parse.com-如何搜索/检索当前用户的安全对象

[英]Parse.com - How to search/retrieve secured object for current uer

As per parse API documentation, "Security For Other Objects". 根据解析API文档,“其他对象的安全性”。

Create a private note that can only be accessed by the current user: 创建只能由当前用户访问的私人注释:

PFObject *privateNote = [PFObject objectWithClassName:@"Note"];
privateNote[@"content"] = @"This note is private!";
privateNote.ACL = [PFACL ACLWithUser:[PFUser currentUser]];
[privateNote saveInBackground];

Link: https://www.parse.com/docs/ios_guide#users-acls/iOS 链接: https//www.parse.com/docs/ios_guide#users-acls/iOS

This note will then only be accessible to the current user, although it will be accessible to any device where that user is signed in. 然后,该注释仅对当前用户可用,尽管该用户登录的任何设备都可以访问。

Question: How to retrieve all my private notes ? 问题:如何检索我所有的私人笔记? Unable to find out in documentation. 无法在文档中找到。

You have one add more column in your note class named "user" it creates user pointer in your table. 您在笔记类中有一个名为“ user”的添加栏,它将在表中创建用户指针。

PFObject *privateNote = [PFObject objectWithClassName:@"Note"];
privateNote[@"content"] = @"This note is private!";
privateNote[@"user"] = [PFUser currentUser];
privateNote.ACL = [PFACL ACLWithUser:[PFUser currentUser]];
[privateNote saveInBackground];

And when you want to retrieve all notes which are related to that user then you can use following code 而且,当您想检索与该用户相关的所有注释时,可以使用以下代码

PFQuery *query = [PFQuery queryWithClassName:@"Note"];
[query whereKey:@"user" equalTo:[PFUser currentUser]];
NSArray *usersNote = [query findObjects];
NSLog(@"%@",usersNote);

in above Array u can get records. 在上面的数组中,您可以获得记录。

Hope this will help to you. 希望这对您有帮助。

Actually I've got another simple solution: 实际上,我还有另一个简单的解决方案:

NO need to create extra column. 无需创建额外的列。 You can simply use this: 您可以简单地使用:

PFObject *privateNote = [PFObject objectWithClassName:@"Note"];
privateNote[@"content"] = @"This note is private!";
privateNote.ACL = [PFACL ACLWithUser:[PFUser currentUser]];
[privateNote saveInBackground];


PFQuery *query = [PFQuery queryWithClassName:@"Note"];
NSArray *usersNote = [query findObjects];
NSLog(@"%@",usersNote);

It will automatically retrieve private note. 它将自动检索私人笔记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM