在Parse中从用户类中检索图像

时间:2014-08-07 14:19:58

标签: ios database parse-platform pfquery

我正在尝试从parse.com检索图像,但无法弄清楚如何!

我使用此代码将图像保存到parse.com中的用户类:

NSData *imageData = UIImageJPEGRepresentation(imageView.image, 1.0);
imageFile = [PFFile fileWithName:@"profilePic" data:imageData];

PFUser *user = [PFUser currentUser];
[user setObject:imageFile forKey:@"imageFile"];

[user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    if (succeeded) {
        NSLog(@"saved");
    }
}];

现在我想要回复相同的图像并将其放在imageView中,我该怎么做?

1 个答案:

答案 0 :(得分:1)

检查getDataInBackgroundWithBlock

PFUser *user = [PFUser currentUser];
PFFile *userImageFile = user[@"imageFile"];
[userImageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
    if (!error) {
        UIImage *image = [UIImage imageWithData:imageData];
    }
}];