The application crashes when you try to share an image from the application on Facebook

advertisements

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


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.