簡體   English   中英

在iOS中從Facebook獲取個人資料照片

[英]Get Profile Photo from Facebook in iOS

我在應用程序中實現了Facebook登錄並獲取了用戶的詳細信息。

我嘗試按照以下方式獲取用戶個人資料圖片:

 FBimage=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[result valueForKeyPath:@"picture.data.url"]]]];

但這需要將近3分鍾的時間,才能使圖片和代碼低於此行,這也會停止執行。

幫我解決這個問題

謝謝

您可以設置AsyncImageView而不是UIImageview以便Image將加載UIImageview

我的圖像也有這類問題。

使用https://github.com/rs/SDWebImage

[imgViewContactImage sd_setImageWithURL:[NSURL URLWithString:@"imagename"]  placeholderImage:[UIImage imageNamed:@"Default"] completed:nil];

首先導入“ UIImageView + WebCache.h”

請嘗試這個。

分享您的反饋。

快樂的編碼。 :)

    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    [login logInWithReadPermissions:@[@"public_profile",@"email",@"picture", @"user_friends"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
        if (error) {
            // Process error

            NSLog(@"efv");
        } else if (result.isCancelled) {
            // Handle cancellations
            NSLog(@"efv");



        } else {
            // If you ask for multiple permissions at once, you
            // should check if specific permissions missing
            if ([result.grantedPermissions containsObject:@"email"]) {
                // Do work
                [self fetchUserDetail];


            }
        }

        [login logOut];

    }];

-(void)fetchUserDetail
{
    if ([FBSDKAccessToken currentAccessToken]) {
        [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name,email,gender,picture"}]
         startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
             if (!error) {


                 NSLog(@"fetched user:%@", result);



             }
             else
             {

             }
         }];
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM