我试图通过以下方式从我的 PFUser 对象中获取文件:
PFFile *userImageFile = gaUser[@"@userImage"];
这将返回零。
这是我的方法中的样子:
- (void)getRemoteImageAndSaveLocalWithObjectId:(NSString *)objectId andType:(NSString *)type{
if ([type isEqualToString:@"user"]) {
PFQuery *query = [GAUser query];
// I tried the include key but I get an error.
//[query includeKey:@"userImage"];
[query getObjectInBackgroundWithId:objectId block:^(PFObject *object, NSError *error) {
GAUser *gaUser = (GAUser *)object;
// this is nil
PFFile *userImageFile = gaUser[@"userImage"];
if (userImageFile){
[userImageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
NSLog(@"in get data");
if (!error) {
NSLog(@"remote image name: %@",data.debugDescription);
UIImage *image = [UIImage imageWithData:data];
}else{
NSLog(@"there was an error");
}
}];
}else{
NSLog(@"user image file is nil");
}
}];
}
打印:user image file is nil
我的解析控制台看起来像:
我做错了什么?
最佳答案
因为在 Parse 中你的列被命名为 userImage
,你应该通过以下方式访问它:
PFFile *userImageFile = gaUser[@"userImage"];
代替
PFFile *userImageFile = gaUser[@"@userImage"];
关于ios - 如何使用 Parse 从 pfobject 获取 pffile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27301624/