-1

I am trying to post image in imageview(display_image) on user's profile by using facebook SDk.Code is Like below.

FBLinkShareParams *params = [[FBLinkShareParams alloc] init];
params.link = [NSURL URLWithString:@"https://developers.facebook.com/docs/ios/share/"];



// If the Facebook app is installed and we can present the share dialog
if ([FBDialogs  canPresentShareDialogWithParams:params]) {

    // Present share dialog
    [FBDialogs presentShareDialogWithLink:params.link
                                  handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
                                      if(error) {
                                          // An error occurred, we need to handle the error
                                          // See: https://developers.facebook.com/docs/ios/errors
                                          NSLog(@"Error publishing story: %@", error.description);
                                      } else {
                                          // Success
                                          NSLog(@"result %@", results);
                                      }
                                  }];

    // If the Facebook app is NOT installed and we can't present the share dialog
} else {

     NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:image_display.image,  @"picture", @"hello",@"caption",nil];

    [FBWebDialogs presentFeedDialogModallyWithSession:nil
                                           parameters:params
                                              handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                                                  if (error) {
                                                      // An error occurred, we need to handle the error
                                                      // See: https://developers.facebook.com/docs/ios/errors
                                                      NSLog(@"Error publishing story: %@", error.description);
                                                  } else {
                                                      if (result == FBWebDialogResultDialogNotCompleted) {
                                                          // User canceled.
                                                          NSLog(@"User cancelled.");
                                                      } else {
                                                          // Handle the publish feed callback
                                                          NSDictionary *urlParams = [self parseURLParams:[resultURL query]];

                                                          if (![urlParams valueForKey:@"post_id"]) {
                                                              // User canceled.
                                                              NSLog(@"User cancelled.");

                                                          } else {
                                                              // User clicked the Share button
                                                              NSString *result = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]];
                                                              NSLog(@"result %@", result);
                                                          }
                                                      }
                                                  }
                                              }];
}

it's working good with out sending image value in params dictionary. Using image app will crash here with below error

reason: '-[UIImage length]: unrecognized selector sent to instance 0x7fdd5a80e160'

can any one help me to solve this problem?

Thanks

Esha
  • 1,328
  • 13
  • 34
user3418619
  • 235
  • 1
  • 2
  • 14

1 Answers1

-1

You cannot post image you can only post image URL Example:-

-(void)fbShare{
// If the Facebook app is installed and we can present the share dialog
if ([FBDialogs canPresentShareDialog]) {

    NSURL *imageURL =   [NSURL URLWithString:@"https://profile_VMGhBTJVM5_1413618023060.jpg"];

    [FBDialogs presentShareDialogWithLink:[NSURL URLWithString:@"http://www.Testinfo.com/"] name:@"name related to link" caption:nil description:@"Testing Desc" picture:imageURL clientState:nil handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
        if(error) {
            // An error occurred, we need to handle the error
            // See: https://developers.facebook.com/docs/ios/errors
            NSLog(@"Error publishing story: %@", error.description);
        } else {
            // Success
            NSLog(@"result %@", results);
        }
    }];

    // If the Facebook app is NOT installed and we can't present the share dialog
} else {
    // FALLBACK: publish just a link using the Feed dialog

    // Put together the dialog parameters
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"testing name", @"name",
                                   @"Testing caption.", @"caption",
                                   @"Desc.", @"description",
                                   @"http://www.Testinfo.com/", @"link",
                                   @"https://profile_VMGhBTJVM5_1413618023060.jpg", @"picture",
                                   nil];

    // Show the feed dialog
    [FBWebDialogs presentFeedDialogModallyWithSession:nil
                                           parameters:params
                                              handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                                                  if (error) {
                                                      // An error occurred, we need to handle the error
                                                      // See: https://developers.facebook.com/docs/ios/errors
                                                      NSLog(@"Error publishing story: %@", error.description);
                                                  } else {
                                                      if (result == FBWebDialogResultDialogNotCompleted) {
                                                          // User canceled.
                                                          NSLog(@"User cancelled.");
                                                      } else {
                                                          // Handle the publish feed callback
                                                          NSDictionary *urlParams = [self parseURLParams:[resultURL query]];

                                                          if (![urlParams valueForKey:@"post_id"]) {
                                                              // User canceled.
                                                              NSLog(@"User cancelled.");

                                                          } else {
                                                              // User clicked the Share button
                                                              NSString *result = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]];
                                                              NSLog(@"result %@", result);
                                                          }
                                                      }
                                                  }
                                              }];
    }
}
abhinav
  • 312
  • 1
  • 11