1

I want to share image,url and text to facebook and I am not able to make it work on iOS9.Here is my code.

-(IBAction)shareOnFacebook:(id)sender{

    UIButton *btn = (UIButton *)sender;

    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
        SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

        [controller setInitialText:SHARING_QUOTE_D(self.dish.name, self.dish.restaurant.name)];
        [controller addURL:[NSURL URLWithString:SHARING_URL]];
        [controller addImage:self.dishImageView.image];


        [self presentViewController:controller animated:YES completion:Nil];

        if ([controller respondsToSelector:@selector(popoverPresentationController)])
        {
            UIPopoverPresentationController *presentationController = [controller popoverPresentationController];
            presentationController.sourceView = btn; // if button or change to self.view.
        }

    }else{
        [[[UIAlertView alloc] initWithTitle:@"Error Message" message:@"Please log into your Facebook account to post" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil] show];
    }

}
Sekhar
  • 341
  • 2
  • 13
  • add a completion handler.... this works for me[facebook setCompletionHandler:^(SLComposeViewControllerResult result) { switch (result) { case SLComposeViewControllerResultCancelled: NSLog(@"Post Canceled"); break; case SLComposeViewControllerResultDone: NSLog(@"Post Sucessful"); break; default: break; } }]; – Divyanshu Sharma Nov 18 '15 at 11:44
  • added it.but still not working. – Sekhar Nov 24 '15 at 09:45

1 Answers1

0

You must use New Facebook SDK for sharing. Also you want Facebook app in the device. The iOS 9 will dismiss the SLComposeView and may be show you alert "....not supported..."

Mohd Sadham
  • 435
  • 3
  • 19