Reputation: 119
I'm new to parse and i've just implemented a facebook log in using parse. In my app i need the facebook profile picture of the person who is logged in. i've created that method, but dont know if there is a simpler way.
This method takes time to load which is not very nice. Can i load the profile picture somehow when the person is logged in and then use it in another viewcontroller?
here is my code at the moment:
// After logging in with Facebook
[FBRequestConnection
startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSString *facebookId = [result objectForKey:@"id"];
image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", facebookId ]]]];
[self.tableView reloadData];
}
}];
Upvotes: 0
Views: 873
Reputation: 77631
This isn't actually anything to do with Parse. It's just Facebook SDK.
What you need to do is store the image somewhere so that you can get it if it already exists.
The easiest (but arguably not best) way is to use a singleton.
Create a singleton object with a property...
@interface MySingleton : NSObject
@property (nonatomic, strong) UIImage *userImage;
+ (instancetype)sharedInstance;
@end
Then you can just check if it exists before downloading...
UIImage *theImage = [[MySingleton sharedInstance] userImage];
if (!theImage) {
// download the image from Facebook and then save it into the singleton
}
Once it is downloaded you can then just get it from the singleton without having to download it every time.
Upvotes: 1