Reputation: 512
I am dealing with FBProfilePictureView. I have tried following method and it works.
- (void)getUserImageFromFBView
{
UIImage *img = nil;
for (NSObject *obj in [self.profilePictureView subviews]) {
if ([obj isMemberOfClass:[UIImageView class]]) {
UIImageView *objImg = (UIImageView *)obj;
img = objImg.image;
break;
}
}
}
Here, I have to put a delay for calling this method, say 5.0f Again in some cases image downloading is not get completed within this period. Is there any possible way to check whether facebook profile image downloading is completed or not. Also image download delay occurs when user changes profile picture in facebook.
Any help is appreciated. Thanks in advance.
Upvotes: 2
Views: 377
Reputation: 4244
Instead of it Try :
- (void) getFBImage
{
NSString *facebookID = @"";
if (![_resultDictionary objectForKey:@"username"] && ![[_resultDictionary objectForKey:@"username"] isEqualToString:@""])
{
facebookID = [_resultDictionary objectForKey:@"username"];
}
else if ([_resultDictionary objectForKey:@"id"] && ![[_resultDictionary objectForKey:@"id"] isEqualToString:@""])
{
facebookID = [_resultDictionary objectForKey:@"id"];
}
if ([facebookID isEqualToString:@""])
{
return;
}
else
{
NSString *string=[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?width=105&height=109",facebookID];
NSURL *url = [NSURL URLWithString:string];
dispatch_queue_t downloadQueue = dispatch_queue_create("image downloader", NULL);
dispatch_async(downloadQueue, ^{
NSData *imgData = [[NSData alloc] initWithContentsOfURL:url];
dispatch_async(dispatch_get_main_queue(), ^{
[_imgDisplay setImage:[UIImage imageWithData:imgData]];
});
});
}
}
//_imgDisplay is my UIImageView which display Facebook Profile image , _resultDictionary contain Facebook User Id or Username.
Upvotes: 4
Reputation: 10393
You could use a image downloader framework like SDWebImage and track if the image has been downloaded or not using the method
- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url
options:(SDWebImageDownloaderOptions)options
progress:(SDWebImageDownloaderProgressBlock)progressBlock
completed:(SDWebImageDownloaderCompletedBlock)completedBlock;
Upvotes: 0