FBFriendPickerViewController для сохранения фотографий друзей

Можно ли получить юзерпики друзей с помощью FBFriendPickerViewController? Я попытался:

FBFriendPickerViewController *friendPicker = [[FBFriendPickerViewController alloc] init];
friendPicker.fieldsForRequest = [[NSSet alloc] initWithObjects:@"picture", nil];
[friendPicker loadData];
[friendPicker presentModallyFromViewController:self
                                      animated:YES
                                       handler:^(FBViewController *sender, BOOL donePressed) {
                                           if (donePressed) {
UIImage *pic = friend[@"picture"];
...

Но есть nil в friend[@"picture"].


person Shmidt    schedule 29.09.2012    source источник


Ответы (2)


Попробуйте этот код внутри вашего блока, здесь он работает.

if (donePressed) {
   for (id<FBGraphUser> user in self.friendPickerController.selection) {
        UIImage *pic = user[@"picture"];
        NSLog(@"%@",pic);                                              
   }
}
person alexandresoli    schedule 02.10.2012
comment
Журнал показывает, что это NSDictionary с URL-адресом внутри, поэтому я могу получить изображение оттуда. - person Shmidt; 02.10.2012

Решение

NSURL *profilePictureURL = [NSURL URLWithString:friend[@"picture"][@"data"][@"url"]];
                                                               NSURLRequest *profilePictureURLRequest = [NSURLRequest requestWithURL:profilePictureURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0f]; // 

                                                               [NSURLConnection sendAsynchronousRequest:profilePictureURLRequest
                                                                                                  queue:[NSOperationQueue mainQueue]
                                                                                      completionHandler:^(NSURLResponse* response, NSData* receivedData, NSError* error)
                                                                {
                                                                    UIimage *userpic = [UIImage imageWithData:receivedData];
                                                                }];
person Shmidt    schedule 02.10.2012