gpt4 book ai didi

ios - 使用 [PFUser currentUser] 查询本地数据存储不返回任何对象

转载 作者:行者123 更新时间:2023-11-29 10:32:41 25 4
gpt4 key购买 nike

我正在尝试从在线后端以及我的本地数据存储中加载对象。因此我使用了两个不同的查询。先在线查询:

PFQuery *onlineQuery = [PFQuery queryWithClassName:@"Trip"];
[onlineQuery whereKey:@"users" equalTo:[PFUser currentUser]];

[onlineQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
NSLog(@"Trips loaded from server!");
} else {
NSLog(@"Could not load trips from server!");
[onlineQuery cancel];
}
}];

本地数据存储的查询如下所示:

PFQuery *localQuery = [PFQuery queryWithClassName:@"Trip"];
[localQuery whereKey:@"users" equalTo:[PFUser currentUser]];
[localQuery fromLocalDatastore];

[localQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
// at this point the objects array is empty, but should contain objects
NSLog(@"Trips loaded from local datastore!");
}];

问题是,如果我进行在线查询,它会返回与当前用户相关的所有对象。但是本地查询为同一用户返回 0 个对象。我还检查过 currentUser 不为零。如果我删除行 [localQuery whereKey:@"users"equalTo:[PFUser currentUser]]; 本地查询返回所有对象,这意味着它们已成功保存。将对象保存到本地数据存储时的方法也返回它已成功保存。

PFObject *newTrip = [PFObject objectWithClassName:@"Trip"];

PFRelation *rel = [newTrip relationForKey:@"users"];
[rel addObject:[PFUser currentUser]];

[newTrip pinInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded) {
// succeeded is YES, therefore saving was succesful
NSLog(@"Trip saved to local datastore");
}
}];

最佳答案

根据我们上面的讨论;

如果您有一个事件的 PFUser session ,那么该用户将自动被指定为所有者。即使您没有当前 session 并且没有 [PFUser currentUser] 设备也拥有本地数据存储。目前,本地数据存储是偏见。由于应用程序是沙盒化的,并且您在自己的资源包之外没有写入权限,因此其他用户无法更改更改/更新您的本地数据存储。即使有后端,您也不能更新 User 类中的任何用户信息,除非您是当前用户或具有写入权限。对于本地数据存储,无论 session 如何,它始终假定您是“当前用户”。但是,如果您确实想忽略本地数据存储中 protected 信息的角色,您可以在此处查看他们的注释:

https://parse.com/docs/ios_guide#users-lds/iOS

The same security model that applies to objects in Parse applies to objects in the Local Datastore. Read-write permissions are defined by PFACLs and a user cannot access or modify anything they don't have permission to.

The only difference is that you won't be able to access any data protected by Role based ACLs due to the fact that the Roles are stored on the server. To access this data protected by Role based ACLs, you will need to ignore ACLs when executing a Local Datastore query

但是,考虑到您的情况,我认为您不需要这样做。

关于ios - 使用 [PFUser currentUser] 查询本地数据存储不返回任何对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28808636/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com