1

I Am trying to just post an image with small description on Facebook through my iOS6 app. I Am using SLComposeViewController for this:

   if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {            

        SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

        NSString *shareText = @"This is my art using MyApp";
        [mySLComposerSheet setInitialText:shareText];

        **[mySLComposerSheet addImage:self.mainImage.image];**

        [mySLComposerSheet addURL:[NSURL URLWithString:@"https://itunes.apple.com/in/app/myApp/id665759410?mt=8"]];

        [mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {

            switch (result) {
                case SLComposeViewControllerResultCancelled: {
                    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Could not post on your wall" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil];
                    [alert show];
                    NSLog(@"Post Canceled");
                    break;
                }
                case SLComposeViewControllerResultDone:
                {
                    NSLog(@"Post Sucessful");
                    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Success" message:@"Posted succesfully on your wall" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil];
                    [alert show];
                    break;
                }
                default:
                    break;
            }
        }];

        [self presentViewController:mySLComposerSheet animated:YES completion:nil];
    }

This is currently the code I use for posting to Facebook. But this doesn't show up the image during the post, instead there is a blank safari logo in place of it. I don't understand what's going wrong here. Can anybody help?

sakibmoon
  • 2,026
  • 3
  • 22
  • 32
nuteron
  • 531
  • 2
  • 8
  • 26

1 Answers1

0

This is because of the addURL: iOS automatically add the Safari preview of the url, and since it has not yet loaded, it shows the safari preview, just like this one

https://stackoverflow.com/a/14265411/474330

Community
  • 1
  • 1
Zennichimaro
  • 5,236
  • 6
  • 54
  • 78