Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setInitialText method in SLComposeViewController iOS 8.3 does not show text in Facebook sheet

The code snippet below is the callback for an on screen button. The Facebook sheet appears but contains no text. However, if you replace SLServiceTypeFacebook with SLServiceTypeTwitter it does show the initial text. I am using XCode 6.3.1 and iOS 8.3 on an iPhone 6. Thank you in advance.

-(IBAction)facebookButton:(id)sender
{
    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
    {
        NSString* facebookText = @"Awesome App";
        SLComposeViewController *fbPostSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
        [fbPostSheet setInitialText:facebookText];
        [self presentViewController:fbPostSheet animated:YES completion:nil];
    }
    else{
         UIAlertView *alertView = [[UIAlertView alloc]
                              initWithTitle:@"Unable to Connect to Facebook"
                              message:@"Make sure your device has an internet connection and you have your Facebook account setup in the Settings App"
                              delegate:self
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil];
        [alertView show];
    }
}        
like image 213
Graham French Avatar asked Apr 29 '15 12:04

Graham French


2 Answers

If you delete the Facebook app on the device, the initial text will appear.

like image 195
Chrisswong Avatar answered Oct 15 '22 20:10

Chrisswong


It actually works if you set the text inside the completion handler:

NSString* facebookText = @"Awesome App";
SLComposeViewController *fbPostSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
//[fbPostSheet setInitialText:facebookText];
[self presentViewController:fbPostSheet animated:YES completion:^
{
    [fbPostSheet setInitialText:facebookText];
}];
like image 28
Asif Asif Avatar answered Oct 15 '22 19:10

Asif Asif