【问题标题】:PFObject won't save PFFile PArsePFObject 不会保存 PFFile PArse
【发布时间】:2014-08-07 16:35:10
【问题描述】:

我似乎无法将 Pffile 对象设置为 Objective-C 中 Pfobject 键的值。我正在尝试将来自 AVAudioPlayer 的 NSData 保存在 PFfile 中。 如果我执行以下操作:

NSData * audioData=[self.shoutInfoArray objectAtIndex:1];
PFFile * audiofile=[PFFile fileWithName:@"shoutData" data:audioData];
bool saved=[audiofile save]; //This bool is positive, so it does save!?
[shout fetchIfNeeded];
shout[@"audioData"]=audiofile; //BUGGY LINE

我收到以下错误:

错误:关键音频数据的类型无效,预期字节,但得到文件 (代码:111,版本:1.2.20)

找不到原因?

【问题讨论】:

    标签: ios parse-platform pffile pfobject


    【解决方案1】:

    清除您的数据库。我的意思是删除列audioData。它与类型接缝有问题。

    【讨论】:

      【解决方案2】:

      将 PFFile 对象保存为 PFObject 的一部分:同时检查文件大小不应大于 10MB。

      PFFile * audiofile=[PFFile fileWithName:@"shoutData.aif" data:audioData];
      
      [imageFile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
      
       //Use async call.
       // It is compulsory to save the PFFile object first and then used it with PFObject
      
        if(succeeded)
        {
          PFObject *shout = [PFObject objectWithClassName:@"UserData"];
          shout[@"audioData"] = audiofile;
          [shout saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
      
              if(error)
              {
                  NSLog(@"error %@",error.localizedDescription);
      
              }
              else
              {
                  if(succeeded)
                  {
                      NSLog(@"object save on parse");
                  }
              }
          }];
        }
      
      }];
      

      【讨论】:

      • 您好,感谢您的及时回复。我检查了文件大小,它只有几个 100 kb。此外,PFFile 保存成功。但我仍然得到错误。
      • 我实际上只是复制并提出了您的回复,但仍然失败。
      • @DavidJackson 我修改了我的代码。只需检查内部块中生成的错误。
      • 并抛出错误:错误:key audioData 的类型无效,预期字节,但得到文件(代码:111,版本:1.2.20)
      • 更奇怪的是,如果我将该行替换为:喊[@"audioData"] = @"test";我收到错误 Error: invalid type for key audioData, expected bytes, but got string (Code: 111, Version: 1.2.20) 这是怎么回事?我应该可以在 PFObjects 中保存字符串,对吧?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-07
      • 1970-01-01
      • 2015-03-23
      • 1970-01-01
      • 2015-03-26
      • 1970-01-01
      相关资源
      最近更新 更多