2014-01-13 221 views
2

我正在處理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中的個人資料圖片時,圖片下載延遲也會發生

任何幫助表示讚賞。提前致謝。

回答

0

你可以使用一個圖像下載框架像SDWebImage和跟蹤如果圖像已被下載或不使用的方法,而不是它的

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

是否可以使用FBProfilePictureView這樣的框架? – QUserS

+0

我假設你通過graph-api獲得用戶的圖像,這基本上是一個url。 –

+0

使用FBProfilePictureView時,不需要調用graph-api。只需將fbUserId設置爲FBProfilePictureView的配置文件ID即可。它會獲取並顯示用戶圖片。 – QUserS

4

嘗試:

- (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是我的顯示Facebook個人資料圖片的UIImageView,_resultDictionary包含Facebook用戶名或用戶名。

+0

謝謝!它只需稍作修改即可正常工作。最好使用用戶名而不是用戶名。然後在Facebook上的個人資料圖片更改將很容易更新(但我想知道爲什麼!!) – QUserS

+0

然後標記爲正確答案&投票男人:P – Xeieshan