0

I want to share photo and some text from the app on Facebook. I used SLComposeViewController class for sharing.

My problem is that when I tap on Facebook button a dialog box appears with image which I want to post but default text is not appearing in the device while in simulator it works perfectly fine. This code works perfectly for Twitter both in simulator and device. For more clarity I added code and an image

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
    SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
    
    SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result)
    {
        if (result == SLComposeViewControllerResultCancelled)
        {
            NSLog(@"Cancelled");
            
        } else
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Congratulations!" message:@"Photo is posted to facebook Wall." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
            [alert show];
        }
        [controller dismissViewControllerAnimated:YES completion:Nil];

    };
    
    controller.completionHandler =myBlock;
    str=[NSString stringWithFormat:@"Text to share"];
    
    [controller setInitialText:str];
    [controller addImage:savedImage];
    [self presentViewController:controller animated:YES completion:Nil];
}

enter image description here

Community
  • 1
  • 1
Indrajeet
  • 5,490
  • 2
  • 28
  • 43

2 Answers2

0
str=@"Text to share";

[controller setInitialText:str];


          OR
[controller setInitialText:@"Text to share"];

change your code like this and try...

vijeesh
  • 1,317
  • 1
  • 17
  • 32
0
- (IBAction)facebookPost:(id)sender {

    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

        SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

        [mySLComposerSheet setInitialText:@"Social Framework test!"];

        [mySLComposerSheet addImage:[UIImage imageNamed:@"myImage.png"]];

        [mySLComposerSheet addURL:[NSURL URLWithString:@"http://stackoverflow.com"]];

        [mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {

             switch (result) {
                 case SLComposeViewControllerResultCancelled:
                     NSLog(@"Post Canceled");
                     break;
                 case SLComposeViewControllerResultDone:
                     NSLog(@"Post Sucessful");
                     break;

                 default:
                     break;
             }
         }];

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

Try this........This what I did for my project

vijeesh
  • 1,317
  • 1
  • 17
  • 32