这就是我收集用户个人资料图片的方式,尽管有很多方法可以做到这一点:
一旦用户登录,我将使用通知(或任何其他方法)进行通知,然后调用方法来收集 Facebook 个人资料图片。一旦他们登录,您就可以将他们的 facebook Id 传递给一个值。(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];
注意:您需要将标题更新为 < NSURLConnectionDataDelegate
> 并为NSMutableData *_data;
然后处理响应:
#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];
}
然后你可以对文件做你想做的事。通常我缓存文件,然后检查缓存的文件是否与新文件匹配,依此类推......