OGeek|极客世界-中国程序员成长平台

标题: ios - FBProfilePictureView 加载延迟 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 05:56
标题: ios - FBProfilePictureView 加载延迟

我正在处理 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 中更改个人资料图片时,也会出现图像下载延迟。

感谢任何帮助。提前致谢。



Best Answer-推荐答案


试试吧:

- (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 或用户名。

关于ios - FBProfilePictureView 加载延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21085801/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4