[英]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.