Camus
Camus

Reputation: 846

Return Facebook profile picture

Is that possible to retrieve the name of the picture file from the Facebook profile picture?

What I want to do is this: When the user logs in I will retrieve the user's profile pic and then save it on a file. However, I want to always check whether the user updated the picture on Facebook and if yes save it on the file again.

Is it possible to get the name of the file, and therefore I can compare them?

Here is the code that I use to download the picture:

NSString *urlString = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?width=100&height=100",[[PFUser currentUser] objectForKey:@"fbId"]];                
    NSURL *url = [NSURL URLWithString:urlString];
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];

    AFHTTPRequestOperation *requestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest];
    requestOperation.responseSerializer = [AFImageResponseSerializer serializer];

    [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject){
        profilePicture = [UIImage imageWithData: operation.responseData];
        NSDictionary<FBGraphUser> *me = (NSDictionary<FBGraphUser> *)responseObject;
        NSLog(@"ResponseObject %@", me.username);
        NSLog(@"Profile Image %@",profilePicture);
        [self saveImageOnDisk:profilePicture];
}];

Upvotes: 0

Views: 179

Answers (1)

quellish
quellish

Reputation: 21244

You should not need to do either. Request it again. The URL loading subsystem will check it's cached version and send Facebook an If-Modified-Since (conditional GET) request to check for a newer version. You do not have to do anything special, the system does this for you. If there is newer data available it will get it, otherwise it will use the data it already cached.

URL Loading System: Understanding Cache Access

RFC2616: HTTP Caching

Upvotes: 1

Related Questions