问题
I'm saving images to disk for my app users, who either upload a picture or connect with facebook and we display their profile picture.
This works great, but if a user changes their facebook profile picture, the code below never updates the image.
How can I check the facebook graph api
to check if the image has been uploaded without redownloading the image? I am using AFNetworking
so checking the 302
header is an option if its possible-just not sure how to implement.
//load image if exists on disk
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *filePath = [documentsPath stringByAppendingPathComponent:uniqueCustomerPath];
BOOL fileExists = [fileManager fileExistsAtPath:filePath];
if(fileExists){
UIImage* tempImage = [UIImage imageWithContentsOfFile:filePath];
completionHandler(tempImage);
}
//download image if not
else{
NSString *imageUrl=[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", (long)self.customer.facebook_id];
UIImage *tempImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]]];
NSData *myData = UIImageJPEGRepresentation(tempImage, 1);
[myData writeToFile:filePath atomically:YES];
completionHandler(tempImage);
}
来源:https://stackoverflow.com/questions/29811388/cache-facebook-profile-picture-ios