繁体   English   中英

FBProfilePictureView加载延迟

[英]FBProfilePictureView loading delay

我正在处理FBProfilePictureView。 我尝试了以下方法,它可以工作。

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

在这里,我不得不延迟调用此方法,例如5.0f,在某些情况下,在此期间内无法完成图像下载。 有没有可能检查Facebook个人资料图像下载是否完成的方法。 当用户更改facebook中的个人资料图片时,也会出现图像下载延迟。

任何帮助表示赞赏。 提前致谢。

代替它尝试:

- (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是我的UIImageView,它显示Facebook个人资料图像,_resultDictionary包含Facebook用户ID或用户名。

您可以使用SDWebImage这样的图像下载器框架,并使用方法跟踪图像是否已下载

- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url
                                         options:(SDWebImageDownloaderOptions)options
                                        progress:(SDWebImageDownloaderProgressBlock)progressBlock
                                       completed:(SDWebImageDownloaderCompletedBlock)completedBlock;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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