This is how I would collect the User Profile picture, although there are plenty of ways to do this:
I would use a notification (or any other method) to notify once the user is signed in, then call a method to collect the Facebook Profile picture. Once they are logged in you can pass their facebook Id to a value. (kUserFacebookIDKey)
NSLog(@"Downloading user's profile picture");
// Download user's profile picture
NSURL *profilePictureURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", self.kUserFacebookIDKey];
NSURLRequest *profilePictureURLRequest = [NSURLRequest requestWithURL:profilePictureURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0f]; // Facebook profile picture cache policy: Expires in 2 weeks
[NSURLConnection connectionWithRequest:profilePictureURLRequest delegate:self];
Note: You would need to update your header to <NSURLConnectionDataDelegate
> and add a property for NSMutableData *_data;
Then handle the response:
#pragma mark - NSURLConnectionDataDelegate
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
_data = [[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[_data appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[TESTUtility processFacebookProfilePictureData:_data];
}
Then you can do what you wish with the file. Typically I cache the file and then check if the cached file matches the new and so on...