2

我有几个类,其中一个是用户,另一个是 TestObject。如果我查询用户(我通过试验和错误了解到它应该作为 _User 查询)我得到正确的记录计数,但是如果我查询 TestObject 我得到 0。这发生在某些类上,但不是所有类。这是为什么?

PFQuery *query = [PFQuery queryWithClassName:@"_User"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
             if (error) {
                 NSLog(@"Error: %@ %@", error, [error userInfo]);
             } else {
                 NSLog(@"Successfully retrieved %d scores.",objects.count);
             }
}];

这将返回:

2012-10-19 13:55:03.239 TableViewParseDotCom[5497:10103] 成功检索到 24 个分数。

但是,如果我将行更改为:

PFQuery *query = [PFQuery queryWithClassName:@"TestObject"];

我得到 0 计数,但我知道我有 45 条记录。为什么?

4

3 回答 3

1

最常见的原因是您查询了您无权访问的对象。仔细检查这些对象是否具有 ACL,您是否以同一用户身份登录。

于 2012-10-20T23:54:52.833 回答
1

除了检查您正在查询的对象的 ACL 之外,您还应该查看 Parse 仪表板中的设置。如果您不想强制用户登录,请确保将“允许匿名用户”设置为“开”。

此外,在 TestObject 对象的数据浏览器中,单击“更多”按钮,然后从下拉列表中选择“权限”。确保您的“查找”和“获取”设置正确 - 设置为公开,没有角色/用户可以帮助您进行调试。这应该确保您可以查询您的 TestObject 对象。

于 2012-10-27T03:35:30.243 回答
0

Don't forget to set the read permissions. These can be programatically set as below:

PFACL * defaultACL = [PFACL ACL];
[defaultACL setPublicReadAccess:YES];
[PFACL setDefaultACL:defaultACL withAccessForCurrentUser:YES];

I just ran two queries, one on my users and one on another class (imageClass) and they both returned fine.

User query:

// Remember for users we can run a user query instead of needing to specify the class
PFQuery * userQuery = [PFUser query];
[userQuery whereKey:@"username" equalTo:currentUser.username];

[userQuery findObjectsInBackgroundWithBlock:^(NSArray * objects, NSError *error) {

}];

Other class query:

PFQuery * imageQuery = [PFQuery queryWithClassName:@"bImageClass"];

[imageQuery findObjectsInBackgroundWithBlock:^(NSArray * objects, NSError *error) {

}];

Here is a picture of my classes in Parse.

parsemenu

So I would make sure you have the public access set correctly (in my project this is set just before a query runs) as the code you are using for the queries looks fine.

于 2015-07-29T09:39:29.650 回答