jakenberg
jakenberg

Reputation: 2113

Facebook iOS SDK FBProfilePictureView not fetching or displaying image

I have the following code in my View Controller

if (FBSession.activeSession.isOpen) {
    [[FBRequest requestForMe] startWithCompletionHandler:
     ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
         if (!error) {
             self.nameString = user.name;
             self.profileImage.profileID = [user objectForKey:@"id"];
             [self.tableView reloadData];
         }
     }];
}

And I'm experiencing two issues. The first is that the profile image is never fetched and displayed. The second is that I have to [self.tableView reloadData] in order for the name to show up. This causes an ugly lag. How do I fix both?

Upvotes: 0

Views: 1328

Answers (1)

combinatorial
combinatorial

Reputation: 9561

I do not know why your profile image is not fetched, but I had a problem with some profile images not being displayed and it lead me to write a modified version of the FBProfilePictureView which is here. This has a completion handler that gets called with error details if the download fails. (In my case I believe the problem was that I sent out too many requests in a short period and my firewall blocked some of them).

As for having to reload the whole table, it depends where you are showing it. I assume in a cell? If so then when you are creating the cell, do:

    CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    if (FBSession.activeSession.isOpen) {
        [[FBRequest requestForMe] startWithCompletionHandler:
            ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
                   if (!error) {
                         cell.profileImage.profileID = user.id;
                   }
             }];
    }

Also, just to note you can use user.id and user.name to access the results of the requestForMe query.

Upvotes: 1

Related Questions