我试图从我上传到Parse的文件中检索一些文本,但我尝试的任何内容似乎都无法正常工作。我尝试使用Parse提供的示例,但我无法使其工作。有人可以帮我解释一下我怎么能这样做吗?
这是一个例子:
PFFile *applicantResume = anotherApplication[@"applicantResumeFile"];
NSData *resumeData = [applicantResume getData];
由于
答案 0 :(得分:0)
您需要将数据转换回字符串,试试这个。
保存
PFObject * anotherApplication = [[PFObject alloc] initWithClassName:@"Resumes"];
NSData *data = [@"Working at Parse is great!" dataUsingEncoding:NSUTF8StringEncoding];
PFFile *file = [PFFile fileWithName:@"resume.txt" data:data];
anotherApplication[@"applicantResumeFile"] = file;
[anotherApplication save];
打开
[anotherApplication fetchIfNeeded];
PFFile *applicantResume = anotherApplication[@"applicantResumeFile"];
NSData *resumeData = [applicantResume getData];
NSString* dataStr = [[NSString alloc] initWithData:resumeData encoding:NSUTF8StringEncoding];
NSLog(@"Received string: %@", dataStr);
不要忘记在实践中,最好使用'getDataInBackgroundWithBlock:','saveInBackgroundWithBlock:'和'fetchIfNeededInBackgroundWithBlock:'
关于街区的说明:
NSLog(@"Will Run 1st: %@", reflex.description); // will be null
[applicantResume getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
NSString* dataStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
reflex.description = dataStr;
NSLog(@"Will Run 3rd: %@", reflex.description); // will contain string.
}];
NSLog(@"Will Run 2nd: %@", reflex.description); // will be null
答案 1 :(得分:0)
PFFile *applicantResume = object[@"applicantResumeFile"];
NSData *resumeData = [applicantResume getData];
NSString* dataStr = [[NSString alloc] initWithData:resumeData encoding:NSUTF8StringEncoding];
reflex.description = dataStr;
itworkы
当我使用getData时,它不是
PFFile *applicantResume = object[@"applicantResumeFile"];
[applicantResume getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {
NSString* dataStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
reflex.description = dataStr;
}
}];