简体   繁体   English

如何将FBProfile图片导入UIImageView

[英]How to get the FBProfile picture into UIImageView

I have an iOS app that integrated with FBLoging. 我有一个与FBLoging集成的iOS应用。 And I know it can assign the profile picture into a UIView like this. 而且我知道它可以像这样将个人资料图片分配到UIView

// This method will be called when the user information has been fetched - (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user { self.profilePictureView.profileID = user.id; }

But what I wanna do is to get that profile picture into my already available UIImageView . 但是我想做的就是将个人资料图片放入我已经可用的UIImageView In order to do this I have a Singleton class. 为此,我有一个Singleton类。 I want to get that image as a UIImage and assign to the variable inside that Singleton class. 我想将该图像作为UIImage并分配给该Singleton类内的变量。 When another Viewcontroller load I want to assign that singleton class's UIImage into my Viewcontroller 's UIImageView 当另一个Viewcontroller加载时,我想将该单例类的UIImage分配到ViewcontrollerUIImageView

How can I do this. 我怎样才能做到这一点。 please help me. 请帮我。 Thank you 谢谢

You can get the image from the profilePictureImageView using this answer . 您可以使用此答案从profilePictureImageView获取图像。 Once you have the image, then you can save it in your Singleton class as is or you can assign it to your imageView. 拥有图像后,您可以按原样将其保存在Singleton类中,也可以将其分配给imageView。

The method in the link only works once the image has been downloaded into the profilePictureImageView. 链接中的方法仅在将图像下载到profilePictureImageView后才起作用。 So you need to take care of that, maybe by waiting. 因此,您可能需要等待,以解决此问题。 Or keep checking it for non nil value after some time in succession. 或连续一段时间后继续检查其非零值。

you can try following method 您可以尝试以下方法

[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *FBuser, NSError *error) {
    if (error) {
      // Handle error
    }

    else {
      NSString *userName = [FBuser name];
      NSString *userImageURL = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", [FBuser id]];
    }
  }];

you have to store this url into your singleton class 您必须将此网址存储到您的单例类中

If you have Facebook user.id with you, you can create the imageURL like this 如果您拥有Facebook user.id,则可以创建像这样的imageURL

   NSString * url = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large",user.objectID];

Then save this url to your singleton class. 然后将此网址保存到您的单例类中。 And you can download like this if you need.(You can download each time you required or download once and save in to a file, if required ,fetch from file). 并且,您可以根据需要下载这样的文件。(您可以在每次需要时下载,也可以下载一次并保存到文件中,如果需要,可以从文件中获取)。

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]]];
UIImage *userImage = [UIImage imageWithData:data];

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

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