如何使用Parse从pfobject获取pffile

时间:2014-12-04 18:46:09

标签: ios objective-c parse-platform

我试图通过简单地从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

我的解析控制台如下:

enter image description here

我做错了什么?

1 个答案:

答案 0 :(得分:4)

由于在Parse中您的列名为userImage,因此您应该使用以下命令访问它:

PFFile *userImageFile = gaUser[@"userImage"];

而不是

PFFile *userImageFile = gaUser[@"@userImage"];