[英]Parse.com - How to search/retrieve secured object for current uer
根據解析API文檔,“其他對象的安全性”。
創建只能由當前用戶訪問的私人注釋:
PFObject *privateNote = [PFObject objectWithClassName:@"Note"];
privateNote[@"content"] = @"This note is private!";
privateNote.ACL = [PFACL ACLWithUser:[PFUser currentUser]];
[privateNote saveInBackground];
鏈接: https : //www.parse.com/docs/ios_guide#users-acls/iOS
然后,該注釋僅對當前用戶可用,盡管該用戶登錄的任何設備都可以訪問。
問題:如何檢索我所有的私人筆記? 無法在文檔中找到。
您在筆記類中有一個名為“ user”的添加欄,它將在表中創建用戶指針。
PFObject *privateNote = [PFObject objectWithClassName:@"Note"];
privateNote[@"content"] = @"This note is private!";
privateNote[@"user"] = [PFUser currentUser];
privateNote.ACL = [PFACL ACLWithUser:[PFUser currentUser]];
[privateNote saveInBackground];
而且,當您想檢索與該用戶相關的所有注釋時,可以使用以下代碼
PFQuery *query = [PFQuery queryWithClassName:@"Note"];
[query whereKey:@"user" equalTo:[PFUser currentUser]];
NSArray *usersNote = [query findObjects];
NSLog(@"%@",usersNote);
在上面的數組中,您可以獲得記錄。
希望這對您有幫助。
實際上,我還有另一個簡單的解決方案:
無需創建額外的列。 您可以簡單地使用:
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);
它將自動檢索私人筆記。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.