0

I have an iOS app that integrated with FBLoging. And I know it can assign the profile picture into a UIView like this.

// 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. In order to do this I have a Singleton class. I want to get that image as a UIImage and assign to the variable inside that Singleton class. When another Viewcontroller load I want to assign that singleton class's UIImage into my Viewcontroller's UIImageView

How can I do this. please help me. Thank you

user2889249
  • 899
  • 2
  • 13
  • 22

3 Answers3

1

You can get the image from the profilePictureImageView using this answer . Once you have the image, then you can save it in your Singleton class as is or you can assign it to your imageView.

The method in the link only works once the image has been downloaded into the 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.

Community
  • 1
  • 1
vishalv2050
  • 813
  • 1
  • 10
  • 18
  • according to that answer when I give it,, it exit from the for loop by giving profilepictureView nil y is that? – user2889249 Jul 04 '14 at 05:37
  • Are you sure the image has been downloaded ? Can you try using a wait() for some time and then try it ? – vishalv2050 Jul 04 '14 at 05:47
  • inside the for loop Im checking the img is null or not but the problem is when first time it reaches to the foor loop it exits,, and I checked by giving self.profilePictureView.profileID = user.id; here the user id getting null, but when I put print the user object in debug area id is comming with other data – user2889249 Jul 04 '14 at 05:57
  • send me the debug data – Suhail kalathil Jul 04 '14 at 05:57
  • email = "test@gmail.com"; "first_name" = Fname; gender = male; id = 66666666666666660; "last_name" = Lastname; link = "https://www.facebook.com/app_scoped_user_id/66666666666666660/"; locale = "en_US"; "middle_name" = Middle; name = "Fname Midddle Lname"; timezone = "5.5"; "updated_time" = "2014-06-19T09:23:23+0000"; verified = 1; – user2889249 Jul 04 '14 at 06:01
  • debug data was something like this – user2889249 Jul 04 '14 at 06:01
  • Don't do user.id, get user id like this : user["id"], this looks like to be a dictionary. – vishalv2050 Jul 04 '14 at 12:32
1

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

Ravi
  • 2,441
  • 1
  • 11
  • 30
  • inside which method do I need to do this? – user2889249 Jul 04 '14 at 05:38
  • create -(NSString *)getFacebookPicture{},in your class write that code inside this method,return userImageUrl.then call where you want – Ravi Jul 04 '14 at 05:45
  • can I put inside - (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id)user there is a FBGraphuser object alredy available so can I just put only NSString *userImageURL = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", [FBuser id]]; this line inside my method? – user2889249 Jul 04 '14 at 05:51
  • so you have FBGraphuser object already you can put inside that method – Ravi Jul 04 '14 at 05:58
1

If you have Facebook user.id with you, you can create the imageURL like this

   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];
Suhail kalathil
  • 2,673
  • 1
  • 13
  • 12
  • here when I put user.id it getting null, but when I type the user object I can see id is coming along with the other data – user2889249 Jul 04 '14 at 06:02
  • send me that response to me – Suhail kalathil Jul 04 '14 at 06:04
  • email = "test@gmail.com"; "first_name" = Fname; gender = male; id = 66666666666666660; "last_name" = Lastname; link = "facebook.com/app_scoped_user_id/66666666666666660/";; locale = "en_US"; "middle_name" = Middle; name = "Fname Midddle Lname"; timezone = "5.5"; "updated_time" = "2014-06-19T09:23:23+0000"; verified = 1; – user2889249 Jul 04 '14 at 06:05
  • its enough, you can extract id from here. is it dictionary r8?.send user objects NSLOg. – Suhail kalathil Jul 04 '14 at 06:09
  • that was the user object I got it py typing po user – user2889249 Jul 04 '14 at 06:16
  • po user.id error: property 'id' not found on object of type 'id' error: 1 errors parsing expression – user2889249 Jul 04 '14 at 06:19
  • i think that deprecated.tyr po user.objectID >objectID Typed access to the user ID. @property (retain, nonatomic) NSString *objectID; Discussion: Note this typically refers to the "id" field of the graph object (i.e., equivalent to [self objectForKey:@"id"]) but is differently named to avoid conflicting with Apple's non-public selectors. – Suhail kalathil Jul 04 '14 at 06:22
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/56746/discussion-between-suhail-and-user2889249). – Suhail kalathil Jul 04 '14 at 06:24
  • I had to use [user objectforkey:@"id"]; – user2889249 Jul 04 '14 at 07:54