Retrieving profile picture with parse.com

I set up a profile picture for users following the code here, but I can't seem to retrieve the picture. The code I tried is below please help me out can't seem to figure this out:

PFQuery *query = [PFUser query];
    [query getObjectInBackgroundWithId:@"profilePic" block:^(PFObject *object, NSError *error) {
        if (!error) {
            NSData * imageData = UIImagePNGRepresentation(object);
        }
        else{
           // Error stuff 
        }
}];

Upvotes: 0

Views: 105

Answers (1)

Timothy Walters
Timothy Walters

Reputation: 16874

You've misunderstood the purpose of getObjectInBackgroundWithId:block: ... the first parameter is meant to be the ID of the object you want to get. Inside the block you can then query for properties of the object you've gotten.

e.g. if you want the current user:

PFQuery *query = [PFUser query];
[query getObjectInBackgroundWithId:[PFUser currentUser].objectId block:^(PFObject *user, NSError *error) {
    if (!error) {
        PFFile *profilePic = user[@"profilePic"];
        [profilePic getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
            if (!error) {
                UIImage *image = [UIImage imageWithData:imageData];
            }
        }];
    }
    else{
       // Error stuff 
    }
}];

Upvotes: 1

Related Questions