简体   繁体   中英

Parse get facebook profile picture when user is logged in

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];
     }
 }];

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM