App crashes when attempting to share image from app on facebook

I am trying to share a post from my application to facebook. It works fine when I enter an image link in the 'picture' key but the app crashes when I give one of my own pictures to share. This is the code I am using

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"Magic Photo from Abracadabra Snap!", @"name",@"Edit photos, move objects around,remove photo bombs", @"caption",@"Use  automatic object detector to select objects or make your own custom selection.Remove the unwanted objects or photobomb,or move objects around.Do crazy stuff with your pictures , save and share with friends.", @"description",@"http://www.arkhitech.com/abracadabra/", @"link",tempImageForFacebookShare, @"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([NSString stringWithFormat:@"Error publishing story: %@", error.description]);
                }
            else {

                if (result == FBWebDialogResultDialogNotCompleted)
                {
                    // User cancelled.
                    NSLog(@"User cancelled.");
                }
            else
            {
                // Handle the publish feed callback
                NSDictionary *urlParams = [self parseURLParams:[resultURL query]];

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

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

The image is a 10*10 image and the error is Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage length]: unrecognized selector sent to instance 0xab7b900'. Please guide about this issue

Answers


It does not work with a UIImage, as the Api only allows strings:

picture: Determines the preview image associated with the link. string

Source: Graph API Reference

The picture parameter is the preview image for the link and can't be uploaded.


Your code looks valid, but you're sending a UIImage to Facebook, where it expects a NSArray with UIImages in it.

Please change your NSDictionary code as follows:

@[tempImageForFacebookShare], @"picture",

And see if it has fixed the problem.


Need Your Help

Configuring APC with Drupal

php drupal centos apc opcode-cache

I am working on a website which is hosted on a VPS with CENTOS 5.4 i686 virtuozzo installed. I have a drupal installation on the server which gets around 100s of authenticated users at the same tim...

Are HLists nothing more than a convoluted way of writing tuples?

scala types tuples hlist shapeless

I am really interested in finding out where the differences are, and more generally, to identify canonical use cases where HLists cannot be used (or rather, don't yield any benefits over regular li...