简体   繁体   中英

FBProfilePictureView loading delay

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.

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.

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;

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