带有指针列的iOS Parse.com保存对象提供“用户不允许”错误

时间:2015-11-07 00:45:44

标签: ios objective-c parse-platform

我正在尝试从iOS应用更新Parse.com类中的现有行。在这样做的时候,我从Parse那里得到了这个错误:

This user is not allowed to perform the update operation on City. You can change this setting in the Data Browser. (Code: 119, Version: 1.9.1)

我有两个Parse.com课程:CityBarCity类是只读的(它是一个不会更改的城市列表),Bar类是用户与之交互的类(如添加注释,评级,菜单项等) 。 Bar Pointer上有City列,公共用户的Bar权限全部开启。

以下是一段代码:

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
  PFQuery *query = [PFQuery queryWithClassName:@"Bar"];
  self.bar = [query getObjectWithId:self.barId];
  self.bar.name = @"Foo";
  [self.bar saveInBackground];
}

关于代码片段的一些注意事项:我通过segue从前一个视图控制器传入条形码ID。我也知道这是在主线程上运行Parse查询,它会阻止......我现在只是原型设计,这是无意义的代码。

运行该代码段后,我收到上面列出的错误。正如您在代码中看到的那样,我不会更改城市值,也不会将其包含在查询结果中。我不明白为什么我会收到这个错误。任何意见都将非常感谢!

1 个答案:

答案 0 :(得分:1)

尝试此代码,看看2 NSLog消息是否按照您期望的顺序出现:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    PFQuery *query = [PFQuery queryWithClassName:@"Bar"];
    //self.bar = [query getObjectWithId:self.barId];
    [query getObjectInBackgroundWithId:self.barId block:^(PFObject *result, NSError *error) {
        NSLog(@"query has finished.");
        self.bar = result[0];
    }];
    self.bar.name = @"Foo";
    NSLog(@"Now going to saveInBackground.");
    [self.bar saveInBackground];
}

然后尝试这个,我认为它可能有效,但我不知道你项目的所有细节:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    PFQuery *query = [PFQuery queryWithClassName:@"Bar"];
    //self.bar = [query getObjectWithId:self.barId];
    [query getObjectInBackgroundWithId:self.barId block:^(PFObject *result, NSError *error) {
        self.bar = result[0]; // or result; ??
        self.bar.name = @"Foo";
        [self.bar saveInBackground];
    }];
}
相关问题