我试图通过简单地从PFUser对象获取文件:
PFFile *userImageFile = gaUser[@"@userImage"];
返回nil。
这就是我的方法中的样子:
- (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
我的解析控制台如下:
我做错了什么?
答案 0 :(得分:4)
由于在Parse中您的列名为userImage
,因此您应该使用以下命令访问它:
PFFile *userImageFile = gaUser[@"userImage"];
而不是
PFFile *userImageFile = gaUser[@"@userImage"];